-
Notifications
You must be signed in to change notification settings - Fork 117
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
fix(encoding): Fix double-encoding of HTTP response #220
Conversation
ecba3ea added a call to encode the response body before sending it to the server if the body is of type str. This is the correct behavior for python 3, where str represents a an unencoded string, but is incorrect for python 2. In python 2, str represents an already-encoded string and unicode represents an unencoded string. This is breaking for prometheus monitoring, which is sending already- encoded bytes to the respond() function. In python 2, those have type str, so we're trying to re-encode them. This works fine as long as there are only ASCII characters in the string, but breaks otherwise. In order to support both python 2 and 3, try to use 'unicode' (as exists in 2) and if it's absent assign str to unicode.
I was able to successfully get the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔨 🐛 👬 🔣 💻 📜
@spinnakerbot 🍒 ⛏️ 1.16 |
@spinnakerbot 🍒 ⛏️ 1.16 |
ecba3ea added a call to encode the response body before sending it to the server if the body is of type str. This is the correct behavior for python 3, where str represents a an unencoded string, but is incorrect for python 2. In python 2, str represents an already-encoded string and unicode represents an unencoded string. This is breaking for prometheus monitoring, which is sending already- encoded bytes to the respond() function. In python 2, those have type str, so we're trying to re-encode them. This works fine as long as there are only ASCII characters in the string, but breaks otherwise. In order to support both python 2 and 3, try to use 'unicode' (as exists in 2) and if it's absent assign str to unicode.
Cherry pick successful: #221 |
ecba3ea added a call to encode the response body before sending it to the server if the body is of type str. This is the correct behavior for python 3, where str represents a an unencoded string, but is incorrect for python 2. In python 2, str represents an already-encoded string and unicode represents an unencoded string. This is breaking for prometheus monitoring, which is sending already- encoded bytes to the respond() function. In python 2, those have type str, so we're trying to re-encode them. This works fine as long as there are only ASCII characters in the string, but breaks otherwise. In order to support both python 2 and 3, try to use 'unicode' (as exists in 2) and if it's absent assign str to unicode.
Fixes spinnaker/spinnaker#4980
ecba3ea added a call to encode the response body before sending it to the server if the body is of type str.
This is the correct behavior for python 3, where str represents a an unencoded string, but is incorrect for python 2. In python 2, str represents an already-encoded string and unicode represents an unencoded string.
This is breaking for prometheus monitoring, which is sending already-encoded bytes to the respond() function. In python 2, those have type str, so we're trying to re-encode them. This works fine as long as there are only ASCII characters in the string, but breaks otherwise.
In order to support both python 2 and 3, try to use 'unicode' (as exists in 2) and if it's absent assign str to unicode.