python gevent 报:urlopen error 错误,求救啊!! - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yeelone
V2EX    Python

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

  •  
  •   yeelone 2013-06-25 15:52:49 +08:00 5113 次点击
    这是一个创建于 4509 天前的主题,其中的信息可能已经有所发展或是发生改变。
    以下是看教程中一个例子:

    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()


    会报如下错误 :
    ubuntu@yee:/tmp$ python t3.py
    synchronous:
    Traceback (most recent call last):
    File "t3.py", line 26, in <module>
    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: <urlopen error [Errno 66] unknown>

    如果注释掉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: <urlopen error [Errno 66] unknown>
    <Greenlet at 0x1b02e10: fetch(9)> 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 好歹是程序员的圈子,居然不能贴代码啊,这是什么逻辑?代码一上来全乱了
    2 条回复    1970-01-01 08:00:00 +08:00
    minggl
        1
    minggl  
       2013-06-26 20:45:53 +08:00
    1.gevent.monkey.patch_all(dns=false)试试
    2.换个gevent版本
    yeelone
        2
    yeelone  
    OP
       2013-06-28 14:06:33 +08:00
    @minggl 我把版本换到了 1.0dev 就没有报错了。ths
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     4881 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 05:40 PVG 13:40 LAX 22:40 JFK 01:40
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86