如何获取python请求的ca证书?

wko9yo5t  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(382)

我正在尝试运行一个连接到myhost.comapny.com:8443的python脚本,但它在运行时给出了ssl证书错误

(Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1122)')))

我的代码如下:

import requests

url = "https://myhost.comapny.com:8443/environments/test/deplpyments"

payload={}
files=[
  ('request',('test.yaml',open('test.yaml','rb'),'application/octet-stream'))
]
headers = {
  'Content-Type': 'multipart/form-data',
  'Authorization': 'token'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files,verify="/user/test/company.cert")

print(response.text)

我已将证书添加为:

openssl s_client -showcerts -connect myhost.comapny.com:8443 </dev/null 2>/dev/null | openssl x509 -text >company.cert

但它仍然不起作用,同样的错误也随着ssl验证失败而来。似乎我没有正确生成证书。有人能告诉我如何正确生成证书吗?

h79rfbju

h79rfbju1#

您是否需要验证证书?如果没有,您可以尝试设置“verify=false”。

相关问题