我正在嘗試使用 requests 庫在 python 中實作一個代理,但我一直在重復得到同樣的錯誤。這是我的代碼:
proxies = {
'http'/span>: 'http://127.0.0.1:24000',
'https': 'https://127.0.0.1:24000',
}
resp = requests.get('https://api.myip.com', proxies=proxies)
print(resp.text)
我正在使用Bright Data的代理管理器,我懷疑我對代理的實作是錯誤的。我得到的錯誤是:
我正在使用 Bright Data 的代理管理器,我懷疑我的代理實作是錯誤的。
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.myip.com', port=443)。超過最大重試次數 with url: / (Causeused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verification failed: self signed certificate in certificate chain (_ssl.c:1129)'/span>))
我已經嘗試了網上找到的解決方案,比如verify=false,對這個鏈接有效,但對我需要訪問的其他鏈接卻無效,這就是為什么我在尋找一個更安全的解決方案。
uj5u.com熱心網友回復:
如果你有一份自簽名證書和密鑰的副本,你可以按以下方式修改代碼:
proxies = {
'http'/span>: 'http://127.0.0.1:24000',
'https': 'http://127.0.0.1:24000',
}
certificate_path = os.path.join(CACERT_PATH, 'cacert.pem')
key_path = os.path.join(CACERT_KEY, 'cacert.key')
resp = requests.get('https://api.myip.com',
proxies=proxies。
cert=(certificate_path, key_path))
print(resp.text)
uj5u.com熱心網友回復:
verify=False是一種方法,但禁用這些警告的更好方法是使用這個:
import urllib3
urllib3.disable_warnings()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/329846.html
標籤:
