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

[PR #7995/43a5bc50 backport][3.10] Fix examples of fallback_charset_resolver function in client_advanced documentation #8045

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/7995.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix examples of `fallback_charset_resolver` function in client_advanced documentation. -- by :user:`henry0312`
4 changes: 2 additions & 2 deletions docs/client_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -674,12 +674,12 @@ example, this can be used with the ``chardetng_py`` library.::

def charset_resolver(resp: ClientResponse, body: bytes) -> str:
tld = resp.url.host.rsplit(".", maxsplit=1)[-1]
return detect(body, allow_utf8=True, tld=tld)
return detect(body, allow_utf8=True, tld=tld.encode())

ClientSession(fallback_charset_resolver=charset_resolver)

Or, if ``chardetng_py`` doesn't work for you, then ``charset-normalizer`` is another option::

from charset_normalizer import detect

ClientSession(fallback_charset_resolver=lamba r, b: detect(b)["encoding"] or "utf-8")
ClientSession(fallback_charset_resolver=lambda r, b: detect(b)["encoding"] or "utf-8")
Loading