python gevent MonkeyPatchWarning: Monkey-patching ssl after
Posted xhzd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python gevent MonkeyPatchWarning: Monkey-patching ssl after相关的知识,希望对你有一定的参考价值。
MonkeyPatchWarning: Monkey-patching ssl after
报错原因: 导入包的顺序不正确;
解决: 正确顺序如下:
import gevent from gevent import monkey monkey.patch_all() import requests
完整示例:
import gevent from gevent import monkey monkey.patch_all() import requests def task(method, url, req_kwargs): print(method, url, req_kwargs) response = requests.request(method=method, url=url, **req_kwargs) print(response.url, response.content) # ##### 发送请求 ##### gevent.joinall([ gevent.spawn(task, method=‘get‘, url=‘https://www.python.org/‘, req_kwargs=), gevent.spawn(task, method=‘get‘, url=‘https://www.yahoo.com/‘, req_kwargs=), gevent.spawn(task, method=‘get‘, url=‘https://github.com/‘, req_kwargs=), ]) # ##### 发送请求(协程池控制最大协程数量) ##### # from gevent.pool import Pool # pool = Pool(5) # gevent.joinall([ # pool.spawn(task, method=‘get‘, url=‘https://www.python.org/‘, req_kwargs=), # pool.spawn(task, method=‘get‘, url=‘https://www.yahoo.com/‘, req_kwargs=), # pool.spawn(task, method=‘get‘, url=‘https://www.github.com/‘, req_kwargs=), # ])
参考别人的解决方法:https://blog.csdn.net/baidu_24536755/article/details/80712903
以上是关于python gevent MonkeyPatchWarning: Monkey-patching ssl after的主要内容,如果未能解决你的问题,请参考以下文章
python用from gevent import monkey; monkey.patch_all()之后报ssl等错误