urllib2 and exceptions

robean st1999 at gmail.com
Sun Sep 28 21:44:20 EDT 2008


On Sep 28, 5:33 pm, alex23 <wuwe... at gmail.com> wrote:
> On Sep 29, 5:52 am, robean <st1... at gmail.com> wrote:
>
> > Actually, the problem seems to be that IOError is in my namespace, but
> > the other error classes are not. So,
>
> >    except HTTPError, etc.
>
> > fails, but
>
> >    except urllib2.HttpError, etc.
>
> > works fine. Now, I still don't understand why these classes shouldn't
> > automatically work....
>
> IOError is a standard Python exception. HTTPError & URLError are
> exceptions provided by the urllib2 module. They need to be imported
> from or referenced through urllib2 to be used.

Many thanks for your reply. I was simply under the impression that
'import urllib2' would take care of the namespace issue and simply
import everything in urlib2, making it unnecessary to have to
reference HTTPError and URLError.  Sorry for being dense about this
(I'm very new to Python).. Again, thanks for your help.



More information about the Python-list mailing list