Skip to content

Commit bbe91c9

Browse files
henry0312patchback[bot]
authored andcommitted
Fix examples of fallback_charset_resolver function in client_advanced documentation (#7995)
(cherry picked from commit 43a5bc5)
1 parent 034e5e3 commit bbe91c9

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

‎CHANGES/7995.doc‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 2 additions & 2 deletions
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)