From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sun, 31 May 2026 04:08:44 +0000 (+0200) Subject: [3.14] 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=73d55006d4ce3a75b82cb1ab660ccb1b78364fff;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-141444:fix broken URLs and examples in urllib.request.rst (GH-144863) (#150643) gh-141444:fix broken URLs and examples in urllib.request.rst (GH-144863) * 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 Co-authored-by: Senthil Kumaran --- diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index b857b2a235e1..17e33795f3b9 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -1055,7 +1055,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). @@ -1251,10 +1251,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() - ... - - -