mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
Examples correction in urllib2 howto. Michael Foord
This commit is contained in:
parent
da31a3f0c2
commit
20b50b1984
1 changed files with 5 additions and 5 deletions
|
@ -204,7 +204,7 @@ e.g. ::
|
|||
|
||||
>>> req = urllib.request.Request('http://www.pretend_server.org')
|
||||
>>> try: urllib.request.urlopen(req)
|
||||
>>> except urllib.error.URLError, e:
|
||||
>>> except urllib.error.URLError as e:
|
||||
>>> print(e.reason)
|
||||
>>>
|
||||
(4, 'getaddrinfo failed')
|
||||
|
@ -313,7 +313,7 @@ geturl, and info, methods as returned by the ``urllib.response`` module::
|
|||
>>> req = urllib.request.Request('http://www.python.org/fish.html')
|
||||
>>> try:
|
||||
>>> urllib.request.urlopen(req)
|
||||
>>> except urllib.error.URLError, e:
|
||||
>>> except urllib.error.URLError as e:
|
||||
>>> print(e.code)
|
||||
>>> print(e.read())
|
||||
>>>
|
||||
|
@ -342,10 +342,10 @@ Number 1
|
|||
req = Request(someurl)
|
||||
try:
|
||||
response = urlopen(req)
|
||||
except HTTPError, e:
|
||||
except HTTPError as e:
|
||||
print('The server couldn\'t fulfill the request.')
|
||||
print('Error code: ', e.code)
|
||||
except URLError, e:
|
||||
except URLError as e:
|
||||
print('We failed to reach a server.')
|
||||
print('Reason: ', e.reason)
|
||||
else:
|
||||
|
@ -367,7 +367,7 @@ Number 2
|
|||
req = Request(someurl)
|
||||
try:
|
||||
response = urlopen(req)
|
||||
except URLError, e:
|
||||
except URLError as e:
|
||||
if hasattr(e, 'reason'):
|
||||
print('We failed to reach a server.')
|
||||
print('Reason: ', e.reason)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue