En Tue, 15 Apr 2008 02:54:43 -0300, Penny Y. <pylists@arcor. deescribió:
Same as the function urlopen, you have to qualify URLError with the module
first:
except urllib2.URLErro r, e: ...
Or import both things from urllib2:
from urllib2 import urlopen, URLError
try:
r = urlopen(...)
except URLError, e:
...
--
Gabriel Genellina
import urllib2,sys
try:
r=urllib2.urlop en("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
try:
r=urllib2.urlop en("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
first:
except urllib2.URLErro r, e: ...
Or import both things from urllib2:
from urllib2 import urlopen, URLError
try:
r = urlopen(...)
except URLError, e:
...
--
Gabriel Genellina
Comment