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

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

原代码 :

response = urllib2.urlopen(url)

data = response.read()

改为 

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

2.try except  python3中有更改

except Exception as e:#多了个as

3. gevent访问https时报错;

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

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



原文地址:https://www.cnblogs.com/3nohtyp/p/12692396.html