使用gevent时遇到的一些问题记录

1.urllib2在python3中已经没了,使用urllib3 相应代码也要作更改python

原代码 :git

response = urllib2.urlopen(url)github

data = response.read()url

改成 ssl

http = urllib3.PoolManager()
response = http.request('GET', url)
data = response.datait

2.try except  python3中有更改io

except Exception as e:#多了个asevent

3. gevent访问https时报错;import

MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['urllib3.util (D:\\project\\venv\\lib\\site-packages\\urllib3\\util\\__init__.py)', 'urllib3.util.ssl_ (D:\\project\\venv\\lib\\site-packages\\urllib3\\util\\ssl_.py)'].
monkey.patch_all()request

上述连接已经说明解决方法就是 monkey.patch_all()须要在import urllib3前完成。可是这样又不符合PEP8的规范。目前还不知道有什么更完美的方法

相关文章
相关标签/搜索