簡體   English   中英

我如何使用 .cer 文件作為 python 請求的一部分

[英]How do I use a .cer file as part of a python request

假設我有一個名為 symantec-class3.cer 的 cer 文件,這就是我正在嘗試的:

headers = {"content-type": "application/json"}
api_url = "https://www.someurl.com/search"
pprint.pprint(requests.post(api_url, auth=HTTPBasicAuth(username, password), verify="symantec-class3.cer", data=json.dumps(payload), headers=headers).json())

這不喜歡它並產生以下錯誤:

requests.exceptions.SSLError: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)

如果我將驗證設置為 False,它可以正常工作,但我正在嘗試在本地目錄中使用證書文件。

Python 期望 PEM 格式的證書。

因此,您應該使用 openssl x509 命令從 X509 證書中提取公鑰組件。

.cer 擴展名通常表示二進制 DER 格式,因此此命令應以 pycrypto 可以使用的形式提取公鑰:

openssl x509 -inform der -pubkey -noout -in you.cer >public_key.pem

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM