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的規範。目前還不知道有什麼更完美的方法