Python请求-如何添加多个自己的证书 [英] Python requests - how to add multiple own certificates
问题描述
有没有办法告诉请求库添加多个证书,如指定文件夹中的所有 .pem 文件?
Is there a way to tell the requests lib to add multiple certificates like all .pem files from a specified folder?
import requests, glob
CERTIFICATES = glob('/certs/')
url = '127.0.0.1:8080'
requests.get(url, cert=CERTIFICATES)
似乎只对单个证书有效
我已经搜索了 google 和 python 文档.我发现的最好的教程是中的 SSL 认证部分官方文档.
I already search google and the python doc. The best tutorial I found was the SSL certification section in the official documentation.
推荐答案
一次只能传入一个证书文件.
You can only pass in one certificate file at a time.
要么将这些文件合并为一个 .pem
文件,要么遍历证书文件并依次尝试每个文件,直到连接成功.
Either merge those files into one .pem
file, or loop over the certificate files and try each one in turn until the connection succeeds.
一个.pem
文件可以持有多个证书;将所有文件连接在一起应该是安全的.请参阅 http://how2ssl.com/articles/working_with_pem_files/.
A .pem
file can hold multiple certificates; it should be safe to concatenate all your files together. See http://how2ssl.com/articles/working_with_pem_files/.
这篇关于Python请求-如何添加多个自己的证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!