Python请求:.pem - > .crt +键 [英] Python Requests: .pem -> .crt + key
问题描述
我已经获得了一个.pem文件,用于在XML POST API上进行身份验证。我更喜欢使用Python请求,并在文档中找到我需要将.pem文件转换为服务器认证和密钥。我一直无法找到请求需要什么(什么样的认证)。
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?
有关更多上下文,请参阅< a href =http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification =nofollow> 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
。
推荐答案
p>有请求的行为(请参阅此处的文档),你可以利用这里,而不必生成 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屋!