Skip to content

Commit 437ac47

Browse files
[PR #7995/43a5bc50 backport][3.9] Fix examples of fallback_charset_resolver function in client_advanced documentation (#8044)
**This is a backport of PR #7995 as merged into master (43a5bc5).** Co-authored-by: OMOTO Tsukasa <[email protected]>
1 parent 034e5e3 commit 437ac47

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

CHANGES/7995.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix examples of `fallback_charset_resolver` function in client_advanced documentation. -- by :user:`henry0312`

docs/client_advanced.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,12 @@ example, this can be used with the ``chardetng_py`` library.::
674674

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

679679
ClientSession(fallback_charset_resolver=charset_resolver)
680680

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

683683
from charset_normalizer import detect
684684

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

0 commit comments

Comments
 (0)