简体   繁体   English

Python:使用urllib3超越SSL验证

[英]Python: Surpass SSL verification with urllib3

Connectiing to SSL server is throwing an error: 连接到SSL服务器会引发错误:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

I'm using this urllib3 python library for connecting to server, using this method: 我正在使用此urllib3 python库通过以下方法连接到服务器:

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

How can i ignore SSL verification? 如何忽略SSL验证? Or is there another step for doing this? 还是有另一个步骤可以做到这一点?

Thanks. 谢谢。

You should be able to force urllib3 to use an unverified HTTPSConnection object by overriding the static ConnectionCls property of any ConnectionPool instance. 通过覆盖任何ConnectionPool实例的静态ConnectionCls属性,您应该能够强制urllib3使用未经验证的HTTPSConnection对象。 For example: 例如:

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(...)

For additional reference, you can check some of our tests which do similar overriding. 作为其他参考,您可以检查一些类似的覆盖测试

I've opened an issue to improve our documentation on how and when this should be done. 我已经提出了一个问题,以改进我们的文档以及有关如何以及何时完成此操作的信息。 We always appreciate pull requests, if you'd like to contribute. 如果您愿意提供帮助,我们将始终感谢您的请求。 :) :)

您还可以安装证书库,这可能会有所帮助

pip install certifi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM