[docs] Issue in urllib2 doc for python 3.0 to 3.?

Senthil Kumaran senthil at uthcode.com
Wed Jun 25 23:08:48 CEST 2014


Hello Adrix,

The tutorial mentions about Exception hierarchy and URLError catches
HTTPError exception too.
Once that is caught as e, you can refer to the attributes e.code and
e.reason.

So the current example is good as it is.

Thanks!
Senthil

On Mon, Jun 23, 2014 at 9:21 AM, Adrix Remi <electro.adrix at gmail.com> wrote:

> try:
>     response = urlopen(req)
> except URLError as e:
>     if hasattr(e, 'code'):
>         print('The server couldn\'t fulfill the request.') # HTTPError
> handling
>         print('Error code: ', e.code)
>     elif hasattr(e, 'reason'):
>         print('We failed to reach a server.') # URLError handling
>         print('Reason: ', e.reason)
> else:
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20140625/eebed020/attachment-0001.html>


More information about the docs mailing list