Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python的具有自签名证书的ssl_Python_Ssl_Server_Pem_Cer - Fatal编程技术网

使用python的具有自签名证书的ssl

使用python的具有自签名证书的ssl,python,ssl,server,pem,cer,Python,Ssl,Server,Pem,Cer,我正在尝试使用我的自签名证书用python构建一个简单的服务器。 我使用makecert创建了.cer、.pfx、.pvk文件 context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) context.load_cert_chain(certfile="ServerSSL.cer") Traceback (most recent call last): File "ssl_server.py", line 4, in <

我正在尝试使用我的自签名证书用python构建一个简单的服务器。 我使用makecert创建了.cer、.pfx、.pvk文件

context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.load_cert_chain(certfile="ServerSSL.cer")

Traceback (most recent call last):
  File "ssl_server.py", line 4, in <module>
    context.load_cert_chain(certfile="ServerSSL.cer")
ssl.SSLError: [SSL] PEM lib (_ssl.c:2580)
context=ssl.create\u default\u context(ssl.Purpose.CLIENT\u AUTH)
context.load\u cert\u chain(certfile=“ServerSSL.cer”)
回溯(最近一次呼叫最后一次):
文件“ssl_server.py”,第4行,在
context.load\u cert\u chain(certfile=“ServerSSL.cer”)
ssl.SSLError:[ssl]PEM lib(_ssl.c:2580)
我做错了什么?
我还试图通过更改后缀将我的cer文件转换为pem,但我得到了相同的错误。

当您查看
\u ssl.c:2580
的原始源代码时,您可以看到
ssl\u CTX\u use\u certificate\u chain\u file
失败。由于未设置
pw_info.error
errno
,因此不容易找到原因。问题可能是由
crt
文件引起的。在文本编辑器中打开它,检查文件的外观是否与它应该的外观完全相同-同时验证新行。如果它们不完全匹配,函数调用将失败

2567:    PySSL_BEGIN_ALLOW_THREADS_S(pw_info.thread_state);
2568:    r = SSL_CTX_use_certificate_chain_file(self->ctx, certfile_bytes);
2569:    PySSL_END_ALLOW_THREADS_S(pw_info.thread_state);
2570:    if (r != 1) {
2571:        if (pw_info.error) {
2572:            ERR_clear_error();
2573:            /* the password callback has already set the error information */
2574:        }
2575:        else if (errno != 0) {
2576:            ERR_clear_error();
2577:            PyErr_SetFromErrno(PyExc_IOError);
2578:        }
2579:        else {
2580:            _setSSLError(NULL, 0, __FILE__, __LINE__);
2581:        }
2582:        goto error;
报告还说:

证书必须采用PEM格式,并且必须从主体证书(实际的客户端或服务器证书)开始排序,然后是中间CA证书(如果适用),最后是最高级别(根)CA


使用的是什么Python版本?我的Python版本是2.7.10 32位。您是否签出了这个()是的,我从那里获取了代码。