open python error_python gevent 报:urlopen error 错误,求救啊!!

以下是看教程中一个例子:

import gevent.monkey

gevent.monkey.patch_all()

import gevent

import urllib2

def fetch(pid):

response = urllib2.urlopen("http://www.baidu.com")

result = response.read()

print pid

def synchronous():

for i in range(1,10):

fetch(i)

def asynchronous():

threads = []

for i in range(1,10):

threads.append(gevent.spawn(fetch,i))

gevent.joinall(threads)

print 'synchronous:'

synchronous()

print 'Asynchronous:'

asynchronous()

会报如下错误 :

[email protected]:/tmp$ python t3.py

synchronous:

Traceback (most recent call last):

File "t3.py", line 26, in

synchronous()

File "t3.py", line 16, in synchronous

fetch(i)

File "t3.py", line 9, in fetch

response = urllib2.urlopen("http://www.baidu.com")

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 400, in open

response = self._open(req, data)

File "/usr/lib/python2.7/urllib2.py", line 418, in _open

'_open', req)

File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain

result = func(*args)

File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open

return self.do_open(httplib.HTTPConnection, req)

File "/usr/lib/python2.7/urllib2.py", line 1177, in do_open

raise URLError(err)

urllib2.URLError:

如果注释掉synchonrous函数 ,则报如下的错误 :

Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.8-py2.7-linux-x86_64.egg/gevent/greenlet.py", line 390, in run

result = self._run(*self.args, **self.kwargs)

File "t3.py", line 9, in fetch

response = urllib2.urlopen("http://www.baidu.com")

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 400, in open

response = self._open(req, data)

File "/usr/lib/python2.7/urllib2.py", line 418, in _open

'_open', req)

File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain

result = func(*args)

File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open

return self.do_open(httplib.HTTPConnection, req)

File "/usr/lib/python2.7/urllib2.py", line 1177, in do_open

raise URLError(err)

URLError:

failed with URLError

google了好久,完全没有找到解决方法啊,问别人,别人都说跑在他们的环境上没有问题,我也不知道我的环境有什么问题

>>> import gevent

>>> gevent.__version__

'0.13.8'

Best match: greenlet 0.4.1

greenlet 0.4.1 is already the active version in easy-install.pth

_(:з」∠)_ 到底为什么呀????

v2ex 好歹是程序员的圈子,居然不能贴代码啊,这是什么逻辑?代码一上来全乱了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值