生成证书以用于获取 PEM lib 错误的 python 请求 [英] generating cert for use with python requests getting PEM lib error
问题描述
我有一个应用程序,我正在为使用文档制作自签名证书这里.
I have an application which I'm doing self-signing certificates for using the documentation here.
应用程序将该密钥库加载到码头配置中并正确加载,我在浏览网站时收到不可信认证的警告.
The application loads that keystore into a jetty config and loads properly and I get a warning of an untrusted certification when browsing to the site.
然后我想使用 python 连接到它,我已经尝试了生成证书、pem 等的所有变体.我没有做任何事情让我连接.只需执行以下操作 -
Then I want to use python to connect to it and I've tried all variations of generating a cert, pem, etc. nothing I do gets me to connect. Simply doing the following -
import requests
requests.get('https://servername:8443', cert=('path
o\cert\app.cert', '\\path\to\keystore\keystore'))
给我以下回溯 -
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:Python27libsite-packages
equestsapi.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "C:Python27libsite-packages
equestsapi.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "C:Python27libsite-packages
equestssessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "C:Python27libsite-packages
equestssessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "C:Python27libsite-packages
equestsadapters.py", line 431, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL] PEM lib (_ssl.c:2580)
推荐答案
cert
在请求中用于客户端站点证书,而不是用于 CA 存储.使用 verify
参数指定 CA 文件,例如:
cert
in requests is used for client site certificates, not for the CA store. Use the verify
parameter to specify the CA file, e.g.:
requests.get('https://www.example.com', verify='/etc/ssl/certs/ca-certificates.crt')
这篇关于生成证书以用于获取 PEM lib 错误的 python 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!