gpt4 book ai didi

Python:用urllib3超越SSL验证

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:09 25 4
gpt4 key购买 nike

连接到 SSL 服务器时出现错误:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

我使用这个 urllib3 python 库连接到服务器,使用这个方法:

urllib3.connectionpool.connection_from_url(['remote_server_url'], maxsize=2)

如何忽略 SSL 验证?或者还有其他步骤吗?

谢谢。

最佳答案

您应该能够通过覆盖任何 ConnectionPool 实例的静态 ConnectionCls 属性来强制 urllib3 使用未经验证的 HTTPSConnection 对象。例如:

from urllib3.connection import UnverifiedHTTPSConnection
from urllib3.connectionpool import connection_from_url

# Get a ConnectionPool object, same as what you're doing in your question
http = connection_from_url(remote_server_url, maxsize=2)

# Override the connection class to force the unverified HTTPSConnection class
http.ConnectionCls = UnverifiedHTTPSConnection

# Make requests as normal...
r = http.request(...)

要获得更多引用,您可以使用 check some of our tests 执行类似的覆盖操作。

我已经 opened an issue to improve our documentation 关于应该如何以及何时完成。如果您想做出贡献,我们始终感谢拉取请求。 :)

关于Python:用urllib3超越SSL验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24136740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com