问题描述
目前我们正在使用一种将 CA 证书放在服务器上的方法来访问第三方 API.
Currently we're using an approach of putting CA Certificates on the server to access third party APIs.
certificate_path = os.path.join(CERT_PATH, 'cacert.pem')
certificate_key_path = os.path.join(CERT_PATH, 'cacert.key')
response = requests.get(url, cert=(certificate_path, certificate_key_path))
这是可行的,但我们正在寻找而不是将 CA 证书存储在服务器上,而是出于安全目的(客户提出的安全原因)存储在数据库的 Accounts
表中.
This works,But we're looking for instead of storing CA certificates on the server, store in the Accounts
Table in the database for security purposes (security cause raised by Customer).
所以问题是:
有什么方法可以直接将 CA 证书的字符串传递给
requests
(除了将内容写入临时文件)?
Is there any approach we can directly pass CA cert's string to the
requests
directly (other than writing content in to a temp file)?
是否有其他 http
python 模块支持在 http
获取/发布请求中传递 CA 证书的字符串?
Is any other http
python module support passing CA cert's string in the http
get/post request?
我们应该使用其他方法而不是将它们存储在数据库和服务器上吗?
Is there any other approach we should use instead of storing them in the database and on the server?
推荐答案
如果想在不使用临时文件的情况下做到这一点,可以通过覆盖请求 SSLContext.示例可以在这个答案中看到.
If one wants to do this without using temporary file, it is possible by overriding the requests SSLContext. Sample can be seen in this answer.
这篇关于Python 请求 CA 证书作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!