簡體   English   中英

使用Python請求信任自簽名證書

[英]Trusting self signed certificate with Python requests

我的apache ssl conf有以下配置

#   Server Certificate:
SSLCertificateFile /etc/pki/tls/certs/localhost.crt

#   Server Private Key:
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

我沒有此服務器的CA證書。 我是否仍然可以將localhost.crt安裝到我的客戶端以成功驗證我的服務器?

在客戶端:我正在使用Python請求庫(2.2.1)。 使用默認的CA BUNDLE路徑。 即使我將localhost.crt添加到默認路徑中的cacert.pem,我也無法看到驗證通過。 我看到了例外情況:

    File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 385, in send
    raise SSLError(e)
SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

我做錯了嗎? 我應該只在服務器中添加簽署localhost.crt的CA嗎?

謝謝,維傑

如果你提供了代碼並且更清楚你正在做什么,那么你會得到一個很好的答案。

如果您希望即使使用無效證書也不想收到錯誤,請嘗試使用verify=False屬性。

>>> requests.get('https://kennethreitz.com', verify=False)

如果要使用自定義證書,請將證書放在腳本文件夾中,並使用cert=('/path/client.cert', '/path/client.key')參數。

>>> requests.get('https://kennethreitz.com', cert=('/path/client.cert', '/path/client.key'))

有關詳細信息,請閱讀docs.python-requests.org/en/master/user/advanced/網站

暫無
暫無

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

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