urllib2.urlopen('ur')给出错误

时间:2011-06-03 10:14:40

标签: python urllib2

我是python的新手并试图提取页面的内容。当我urlopen('http://www.google.com')时,我收到以下错误:

File "<stdin>", line 1, in <module>    
  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 391, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 409, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1185, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1160, in do_open
    raise URLError(err)

对此有何解决方案?

1 个答案:

答案 0 :(得分:2)

如果您的网络处于脱机状态,则会出现错误消息