From: Senthil Kumaran Date: Sun, 31 May 2026 19:57:53 +0000 (-0700) Subject: [3.13] gh-141444:fix broken URLs and examples in urllib.request.rst (GH-144863) ... X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=66b940c2f1fcb219bc2277ad5a2af04a0b40abd1;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-141444:fix broken URLs and examples in urllib.request.rst (GH-144863) (#150647) * Doc: fix broken URLs and examples in urllib.request.rst (gh-141444) * Doc: update urllib.request examples to handle gzip compression --------- (cherry picked from commit 0f1f7c7889873deb7c2e2c3f18695bf636e7752c) Co-authored-by: Paper Moon --- diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index 04f5466c1a2c..945c96892f59 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -1007,7 +1007,7 @@ AbstractBasicAuthHandler Objects *headers* should be the error headers. *host* is either an authority (e.g. ``"python.org"``) or a URL containing an - authority component (e.g. ``"http://python.org/"``). In either case, the + authority component (e.g. ``"https://python.org/"``). In either case, the authority must not contain a userinfo component (so, ``"python.org"`` and ``"python.org:80"`` are fine, ``"joe:password@python.org"`` is not). @@ -1203,10 +1203,14 @@ This example gets the python.org main page and displays the first 300 bytes of it:: >>> import urllib.request - >>> with urllib.request.urlopen('http://www.python.org/') as f: - ... print(f.read(300)) - ... - b'\n\n\n - >> import urllib.request - >>> f = urllib.request.urlopen('http://www.python.org/') + >>> f = urllib.request.urlopen('https://www.python.org/') >>> try: - ... print(f.read(100).decode('utf-8')) + ... enc = f.headers.get('Content-Encoding') + ... data = f.read() + ... if enc == 'gzip': + ... import gzip + ... data = gzip.decompress(data) + ... print(data[:100].decode('utf-8', errors='replace')) ... finally: ... f.close() - ... - - -