0
我正在嘗試使用請求模塊向需要ssl身份驗證的端點發出發布請求。我的pem文件在指定的路徑中,包含客戶端證書和私鑰。但是,我不斷收到證書驗證失敗異常。我在nginx日誌中看到,請求甚至從未將它發送到那裏。任何人有任何想法爲什麼?我知道這些證書應該起作用。Python請求模塊。 SSL證書驗證錯誤
params = {
"param_2" : "32100",
"param_1" : "abc"
}
headers = {
"Content-Type" : "application/json"
}
body = json.dumps(params)
r = requests.post(
https://somesite.com/somepath,
data=body,
headers=headers,
timeout=10,
verify="/path/to/cert.pem"
)
Traceback (most recent call last):
File "./somefile.py", line 264, in <module>
start()
File "./somefile.py", line 149, in start
verify="/path/to/cert.pem"
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 88, in post
return request('post', url, data=data, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 448, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 554, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 417, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
是的,它與「verify = False」一起工作。謝謝! – user695624 2014-09-04 05:24:25
verify = False可能不是你想要的..如果你沒有驗證證書,那麼使用SSL是沒有意義的。 – synthesizerpatel 2014-09-04 12:51:38