码迷,mamicode.com
首页 > 编程语言 > 详细

python gevent MonkeyPatchWarning: Monkey-patching ssl after

时间:2019-06-15 20:20:13      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:spawn   pre   hub   key   rgs   www   warning   get   解决方法   

 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

标签:spawn   pre   hub   key   rgs   www   warning   get   解决方法   

原文地址:https://www.cnblogs.com/xhzd/p/11028550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!