解决python使用猴子补丁时引入ssl错误

  1. 首先是requests对https发起请求时报ssl错误
    在这里插入图片描述解决: requests提供了两个参数 1. verify 官方给出的解释为 当参数为False时,请求将接受由提交的任何TLS证书并将忽略主机名不匹配和/或过期证书,这将使您的应用程序容易受到攻击 2. cert 接收一个元组类型即(“cret”,key) 如果是字符串,那么就要传输一个ssl证书路径
    在这里插入图片描述
    所以只需要在发起请求时,加入verify=False
d = requests.get(
    "https://host:port/atps/testCaseTask/webDriverTask?scheduleTaskId=3&testCaseTaskId=5", verify=False)
print(d)
  1. 当然 如果你不得不用到协程gevent并给他打上了猴子补丁,且引入了ssl(如果使用了verify的话)并且报出了一个异常:RecursionError: maximum recursion depth exceeded while calling a Python object
    那么我猜你的代码有可能是这样写的
import requests
from gevent import monkey
monkey.patch_all()
d = requests.get(
    "https://host:port/atps/testCaseTask/webDriverTask?scheduleTaskId=3&testCaseTaskId=5", verify=False)
print(d)

并且刚刚会报出一个异常: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.ssl_ (D:\python\lib\site-packages\urllib3\util\ssl_.py)’, ‘urllib3.util (D:\python\lib\site-packages\urllib3\util\init.py)’].
monkey.patch_all()
这个异常告诉你, 你应该去把这个引入放到最前面去执行,因为他会更改ssl的代码
如果真的是这样的话,那么我建议你将
from gevent import monkey
monkey.patch_all()
这两行代码放到最顶部去 其原因就是让猴子补丁尽早的生效
在这里插入图片描述
感谢各位观看,如有其他问题可以私信我 让我们共同进步

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值