Python 请求:.pem ->.crt + 键 [英] Python Requests: .pem -> .crt + key
问题描述
我得到了一个 .pem 文件,用于在 XML POST API 上进行身份验证.我更喜欢使用 Python 请求,并且在文档中发现我需要将 .pem 文件转换为服务器认证和密钥.我一直无法准确找到 Requests 需要什么(什么样的认证).
I've been given a .pem file for authentication on an XML POST API. I would prefer using Python Requests and have found in the documentation that I need to convert the .pem file to a server certification and key. I have been unable to find exactly what Requests needs (what kind of certification).
我之前不得不对文件进行一些 openssl 转换,但我不是专家.任何人都可以解释请求需要什么样的证书和密钥,以及我如何将 .pem 转换为这些文件?
I've had to do some openssl conversions on files before, but I'm no expert. Can anyone explain what kind of certificate and key is needed by Requests and how I can convert a .pem into those files?
有关请求文档的更多上下文,请参阅http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification
For more context into the Requests documentation please see http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification
您会注意到对 /path/server.crt
和 /path/key
的引用.
You'll notice a reference to /path/server.crt
and /path/key
.
推荐答案
存在请求行为 (参见此处的文档),您可以在此处利用它而无需生成 crt
或密钥文件.
There's a behaviour of requests (see documentation here) that you can take advantage of here without having to generate a crt
or key files.
假设您在此处有 pem
文件:/path/to/certificate.pem
,然后您可以:
Let's say you have the pem
file here: /path/to/certificate.pem
, you can then do:
r = requests.get('https://example.com', verify='/path/to/cetificate.pem')
它应该可以完美运行.
这篇关于Python 请求:.pem ->.crt + 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!