470,604 Members | 2,179 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

Re: a name error

En Tue, 15 Apr 2008 02:54:43 -0300, Penny Y. <py*****@arcor.deescribió:
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

Jun 27 '08 #1
1 3670
or

import sys
from urllib2 import *
try:
r=urllib2.urlopen("http://un-know-n.com/")
except URLError,e:
print str(e)
sys.exit(1)

print r.info()

se python scope and namespaces ..
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Frederik Sørensen | last post: by
3 posts views Thread by Arpan | last post: by
4 posts views Thread by =?Utf-8?B?Sm9obiBTaW1wc29u?= | last post: by
13 posts views Thread by Neil | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.