Skip to content

Commit 43a5bc5

Browse files
authored
Fix examples of fallback_charset_resolver function in client_advanced documentation (#7995)
1 parent 54ceb6f commit 43a5bc5

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
@@ -761,12 +761,12 @@ example, this can be used with the ``chardetng_py`` library.::
761761

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

766766
ClientSession(fallback_charset_resolver=charset_resolver)
767767

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

770770
from charset_normalizer import detect
771771

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

0 commit comments

Comments
 (0)