简体   繁体   中英

Python: Surpass SSL verification with urllib3

Connectiing to SSL server is throwing an error:

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

I'm using this urllib3 python library for connecting to server, using this method:

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

How can i ignore SSL verification? 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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