import urllib2,sysSame as the function urlopen, you have to qualify URLError with the module
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
first:
except urllib2.URLError, e: ...
Or import both things from urllib2:
from urllib2 import urlopen, URLError
try:
r = urlopen(...)
except URLError, e:
...
--
Gabriel Genellina