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

Support content encodings other than utf-8 #67

Open
michaelwooley opened this issue Sep 29, 2023 · 0 comments · May be fixed by #68
Open

Support content encodings other than utf-8 #67

michaelwooley opened this issue Sep 29, 2023 · 0 comments · May be fixed by #68

Comments

@michaelwooley
Copy link

michaelwooley commented Sep 29, 2023

The content attribute is always encoded as "utf-8" (source).

However, we've noticed that https://google.com/ (as of 9/29) now returns content encoded as 'ISO-8859-1'.

This breaks some tests that do an actual http request then play back the result and compare the content attributes.

If you're curious, here is a demo of what happens in a (non-mocked) google.com result:

import requests

url = "https://google.com/"
res = requests.get(url)

print(res.headers['Content-Type']) # 'text/html; charset=ISO-8859-1'
print(res.encoding)  # 'ISO-8859-1'

try:
    res.content.decode("utf8")
except Exception as e:
    print(e)

content = res.content.decode(res.encoding)
@michaelwooley michaelwooley linked a pull request Sep 29, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant