如何在Python中手动信任客户端ssl证书?

时间:2018-06-02 23:35:00

标签: python

以下是错误:requests.exceptions.SSLError:HTTPSConnectionPool(host = '10 .0.0.62',port = 8089):使用url:/ services / auth / login超出了最大重试次数(由SSLError引起(SSLError(1, '[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:833)'),))

我从我发现的一些答案中得到了以下内容,但有些事情仍然不对。我仍然不熟悉在我的应用程序中处理证书。

import requests
import os
import sys

url = "https://10.0.0.62:8089/services/auth/login"
data = {"username":"user",
"password":"pass"}


def override_where():
""" overrides certifi.core.where to return actual location of cacert.pem"""
# change this to match the location of cacert.pem
return os.path.abspath('/Users/revronja/splunk.crt')

# is the program compiled?
if hasattr(sys, "frozen"):
   import certifi.core

   os.environ["REQUESTS_CA_BUNDLE"] = override_where()
   certifi.core.where = override_where

   # delay importing until after where() has been replaced
   import requests.utils
   import requests.adapters
   # replace these variables in case these modules were
   # imported before we replaced certifi.core.where
   requests.utils.DEFAULT_CA_BUNDLE_PATH = override_where()
   requests.adapters.DEFAULT_CA_BUNDLE_PATH = override_where()
   # My first attempt, failed.
   #r = requests.post(url, data=data, verify='splunk.crt')

而不是循环

r = requests.post(url, data=data)

0 个答案:

没有答案