簡體   English   中英

SSL:CERTIFICATE_VERIFY_FAILED 證書驗證失敗

[英]SSL: CERTIFICATE_VERIFY_FAILED certificate verify failed

from lxml import html
import requests


url = "https://website.com/"
page = requests.get(url)
tree = html.fromstring(page.content)
page.content

-> SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 證書驗證失敗 (_ssl.c:748)

我運行此腳本,但出現此錯誤。 我該怎么做?

由於您的 URL 是“內部公司 URL”(如評論中所述),我猜它使用自簽名證書,或者由自簽名 CA 證書頒發。

如果確實如此,您有兩種選擇:

(1) 通過verify參數提供到requests.get()調用的公司 CA(包括完整的中間證書鏈,如果有)的路徑:

requests.get('https://website.lo', verify='/path/to/certfile')

(2) ,完全禁用客戶端證書驗證(但要注意這帶來的所有安全風險,例如簡單的中間人攻擊等):

requests.get('https://website.lo', verify=False)

為了完整起見,requests.request()文檔中描述了相關的verify參數:

 verify -- (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to True.

在不使用SSL的情況下使用以下代碼

from lxml import html
import requests


url = "http://website.com/"
page = requests.get(url)
tree = html.fromstring(page.content)
page.content

暫無
暫無

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

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