Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(encoding): Fix double-encoding of HTTP response (#220)
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.
- Loading branch information