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

add auto detect charset from http body when http headers not seted #2161

Closed
wants to merge 1 commit into from
Closed

add auto detect charset from http body when http headers not seted #2161

wants to merge 1 commit into from

Conversation

likexian
Copy link

@likexian likexian commented Aug 7, 2014

requests detect page's charset/encoding from responsed http headers, but many servers won't set it in headers.

In this case, requests will set the charset/encoding to the default 'ISO-8859-1', and result in decoded error, many Chinese developers get lose and complain.

For example:

print requests.get('http://www.126.com/').text

This commit will detect charset/encoding from http headers, if no, from http body, for most situations, everything goes well now.

@likexian likexian changed the title add auto detect charset from http body content when http headers not seted add auto detect charset from http body when http headers not seted Aug 7, 2014
@Lukasa
Copy link
Member

Lukasa commented Aug 7, 2014

Thanks for this!

This is a change that has been discussed many, many times. A sample of issues that touch it are: #1604, #1774, #1604, #1589, #1588, #1546, and #2042. We also mention it in the documentation here. Though it's an easy mistake to make, in future you really should search both open and closed issues before making a change like this because you'll save yourself time and effort.

We aren't going to merge this. Previously we wouldn't have merged this because of the explanation given in the issues mentioned above (namely, that the behaviour is deliberate, and that we aren't a HTML library so we won't introspect content). Currently, this behaviour is tracked under the open issue #2086, which will change this behaviour in a different way. If you'd found that issue you'd have saved yourself some time.

I'm sorry that we can't take this change, please don't let it dissuade you from continuing to contribute!

@Lukasa Lukasa closed this Aug 7, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants