Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Non-200 responses are parsed as json even when the data isn't json. #92

Closed
mccullocht opened this issue Nov 18, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@mccullocht
Copy link
Contributor

What is the bug?

HTTP Connection implementations will take non-200 responses and parse the data as json to help produce more complete exceptions. They do this even if the response contains data of a different type (like text/plain), triggering log messages.

How can one reproduce the bug?

curl -k -u"admin:wrong" -w"\n%{http_code}\n%{content_type}\n" https://localhost:9200/_cluster/health
Unauthorized
401
text/plain; charset=UTF-8

This condition can also be reproduced in tests for the connection classes that ship with this library.

In our production environment we see this most often when rotating passwords for our client roles: the password changes, a routine operation receives a 401 which we catch as an AuthorizationException, but the library also logs that it could not parse the (plain text) response.

What is the expected behavior?

Do not attempt to parse the response as json when it is not json. This will also cause us to stop logging when parsing fails.

What is your host/environment?
Docker image opensearchproject/opensearch:1.1.0 + security plugin
opensearch-py==1.0.0
Python 3.9.5

Do you have any screenshots?
N/A

Do you have any additional context?
I put up a small PR to fix this.

@axeoman
Copy link
Collaborator

axeoman commented Dec 22, 2021

Thanks again for the contribution 👍

@axeoman axeoman closed this as completed Dec 22, 2021
@mccullocht
Copy link
Contributor Author

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants