[英]OpenSSL crypto error: [('PEM routines', 'PEM_read_bio', 'no start line')]
I am getting the following error when trying to read a certificate:尝试读取证书时出现以下错误:
OpenSSL.crypto.Error: [('PEM routines', 'PEM_read_bio', 'no start line')]
when running OpenSSL.crypto.load_certificate(FILETYPE_PEM, filename)
.运行
OpenSSL.crypto.load_certificate(FILETYPE_PEM, filename)
。 I have made some research but was not able to find an answer specific to my case.我进行了一些研究,但无法找到特定于我的案例的答案。
I tried checking if the file existed with os.path.isfile(filename)
which returns True
, but loading the certificate ONLY raises the error above.我尝试检查文件是否存在
os.path.isfile(filename)
返回True
,但加载证书只会引发上述错误。
Also, when executing on the terminal openssl X509 -in file.pem
, it works like a charm.此外,在终端
openssl X509 -in file.pem
上执行时,它的作用就像一个魅力。
The file.pem looks like this: file.pem 看起来像这样:
-----BEGIN CERTIFICATE-----
<<sensitive data>>
-----END CERTIFICATE-----
It seems to be valid since I able to perform basic openssl
operations on the terminal.这似乎是有效的,因为我能够在终端上执行基本的
openssl
操作。 I am running CentOS 7, if that helps.如果有帮助,我正在运行 CentOS 7。
Any ideas?有什么想法吗?
Thanks!谢谢!
According to http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.load_certificate , load_certificate()
takes a buffer (string will do) containing the certificate, not a filename.根据http://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.load_certificate ,
load_certificate()
需要一个包含证书的缓冲区(字符串可以),而不是文件名。
Your need to do:你需要做的:
with open(filename, "r") as my_cert_file:
my_cert_text = my_cert_file.read()
cert = load_certificate(FILETYPE_PEM, my_cert_text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.