-
Notifications
You must be signed in to change notification settings - Fork 39
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
Text encoding is changed when passing a utf-8 string to content #73
Comments
Interesting! Will investigate, thanks. Debugging help appreciated ;-) |
I've now narrowed it down to the content type heder @konstin . If you set the content type it should work. It would be nice though to default to I already had Here's your example, modified, that should work: import httpx
import respx
with respx.mock() as respx_mock:
text_in = "Gehäusegröße"
respx_mock.get("https://example.com", content=text_in, content_type="text/plain; charset=utf-8")
text_out = httpx.get("https://example.com").text # ^
print(text_in)
print(text_out)
print(text_in == text_out) I need to dig into HTTPX to see how it's solved there, default-wise. Happy to see input or feedback how to best solve this. |
Worth mentioning, RESPX sets a default This might be the problem or the place to fix this issue. When I change this default header to But, if I remove setting the default content type header completely, your test input still works, but unfortunately fails the existing test input |
Thank you for investigating, setting I'd although like a |
Awesome if this could be solved in HTTPX! If/when that HTTPX PR is merged, we'll need to decide if it's enough to just remove mentioned RESPX todo's and the encoding-code with it. |
Update... With HTTPX I've extended the content test with your example in #78 to clarify. Still not sure what to do with our default Content-Type header, or the hard utf-8 content encoding in the response template. |
About the content encoding, I think we should introduce From HTTPX chardet PR:
We can have it set to |
I'd expect that utf-8 characters (such as German umlauts) are returned the way I passed them to
content
, however this is not the case:Versions: respx 0.12.1 and httpx 0.14.3
The text was updated successfully, but these errors were encountered: