Python urllib2错误适用于PC但不适用于raspberrypi

时间:2014-04-19 09:54:51

标签: python urllib2

您好我一直在尝试在Rasberry pi上执行下面的python代码,但遇到了我的电脑上不存在的错误

import urllib2
response = urllib2.urlopen('http://pythonforbeginners.com/')
print response.info()
html = response.read()
# do something
response.close()  

错误如下,但我不明白这里有什么问题,有人可以解释一下发生了什么吗?我已经在pi中安装了urllib2:

Traceback (most recent call last):
  File "testing1.py", line 3, in <module>
    response = urllib2.urlopen('http://pythonforbeginners.com/')
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 401, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 419, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1211, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1181, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno -5] No address associated with hostname>

0 个答案:

没有答案