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