diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst --- a/Doc/howto/urllib2.rst +++ b/Doc/howto/urllib2.rst @@ -144,7 +144,7 @@ >>> data['location'] = 'Northampton' >>> data['language'] = 'Python' >>> url_values = urllib.parse.urlencode(data) - >>> print(url_values) + >>> print(url_values) # The order may differ from below. #doctest: +SKIP name=Somebody+Here&language=Python&location=Northampton >>> url = 'http://www.example.com/example.cgi' >>> full_url = url + '?' + url_values @@ -213,11 +213,14 @@ e.g. :: >>> req = urllib.request.Request('http://www.pretend_server.org') - >>> try: urllib.request.urlopen(req) - >>> except urllib.error.URLError as e: - >>> print(e.reason) - >>> - (4, 'getaddrinfo failed') + >>> try: + ... urllib.request.urlopen(req) + ... except urllib.error.URLError as e: + ... print("Error opening url.") + ... # E.g. "[Errno 8] nodename nor servname provided, or not known" + ... print("Reason:", e.reason) #doctest: +ELLIPSIS + Error opening url. + Reason: ... HTTPError @@ -322,18 +325,17 @@ >>> req = urllib.request.Request('http://www.python.org/fish.html') >>> try: - >>> urllib.request.urlopen(req) - >>> except urllib.error.HTTPError as e: - >>> print(e.code) - >>> print(e.read()) - >>> + ... urllib.request.urlopen(req) + ... except urllib.error.HTTPError as e: + ... print(e.code) + ... print(e.read()) #doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE + ... 404 - - - Error 404: File Not Found - ...... etc... + b'\n\n\nPage Not Found\n + ... Wrapping it Up --------------