+ -
当前位置:首页 → 问答吧 → python: urllib2.urlopen在Linux bash中运行需要DNS支持?

python: urllib2.urlopen在Linux bash中运行需要DNS支持?

时间:2010-11-25

来源:互联网

在Ubuntu Linux下,使用bash, python 2.5,
在使用urllib2.urlopen函数的时候发现老是出现下面的错误:
urllib2.URLError: <urlopen error (-2, 'Name or service not known')>

甚至使用python的命令运行模式下也有这个问题,请问这个问题该怎么解决?

>>> req = urllib2.Request('http://www.voidspace.org.uk')
>>> response = urllib2.urlopen(req)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/urllib2.py", line 124, in urlopen
  return _opener.open(url, data)
  File "/usr/lib/python2.5/urllib2.py", line 381, in open
  response = self._open(req, data)
  File "/usr/lib/python2.5/urllib2.py", line 399, in _open
  '_open', req)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
  result = func(*args)
  File "/usr/lib/python2.5/urllib2.py", line 1107, in http_open
  return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.5/urllib2.py", line 1082, in do_open
  raise URLError(err)
urllib2.URLError: <urlopen error (-2, 'Name or service not known')>


注: 
使用编辑器运行都没有问题的!

作者: toymaker   发布时间: 2010-11-25

没有人知道吗?我觉得是不是我的Shell下面需要配置什么呢?
因为在Eclipse下面都是跑的好好的阿

作者: toymaker   发布时间: 2010-11-25