当我输入无效网址时,我收到以下异常:ValueError: unknown url type: blob
我尝试使用以下代码捕获此错误,但它无效:
try:
req = urllib2.Request(url)
conn = urllib2.urlopen(req)
content = conn.read()
except urllib2.URLError, e:
print 'Error: Invalid URL'
答案 0 :(得分:2)
如果您注意到,基本错误是ValueError
,那么
import urllib2
url = 'blob'
try:
req = urllib2.Request(url)
conn = urllib2.urlopen(req)
content = conn.read()
except ValueError, e:
print 'Error: Invalid URL'