En Tue, 15 Apr 2008 02:54:43 -0300, Penny Y. <[EMAIL PROTECTED]> escribió:
> import urllib2,sys
> try:
> r=urllib2.urlopen("http://un-know-n.com/")
> except URLError,e:
> print str(e)
> sys.exit(1)
>
> print r.info()
>
>
> But got the errors:
>
> Traceback (most recent call last):
> File "t1.py", line 4, in ?
> except URLError,e:
> NameError: name 'URLError' is not defined
Same as the function urlopen, you have to qualify URLError with the module
first:
except urllib2.URLError, e: ...
Or import both things from urllib2:
from urllib2 import urlopen, URLError
try:
r = urlopen(...)
except URLError, e:
...
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list