首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kiwi TCMS Python连接SSL错误

Kiwi TCMS Python连接SSL错误
EN

Stack Overflow用户
提问于 2021-02-16 10:33:43
回答 2查看 265关注 0票数 1

当我尝试运行tcms模块时,我会得到以下错误,但是按照所给出的步骤,

https://tcms-api.readthedocs.io/en/latest/modules/tcms_api.html#module-tcms_api

我在CentOS中使用python 3,通过将证书安装到docker容器来应用我们自己的域和证书。

能否告诉您如何解决SSL证书验证失败错误?

代码语言:javascript
复制
[root@KiwiTCMS-Testcase-Portal docker-compose]# python3 test-api.py
Traceback (most recent call last):
  File "test-api.py", line 5, in <module>
    rpc_client = TCMS()
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tcms_api/__init__.py", line 123, in __init__
    config['tcms']['url']).server
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tcms_api/xmlrpc.py", line 124, in __init__
    self.login(username, password, url)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/tcms_api/xmlrpc.py", line 131, in login
    self.server.Auth.login(username, password)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1452, in __request
    verbose=self.__verbose
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1166, in single_request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1279, in send_request
    self.send_content(connection, request_body)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/xmlrpc/client.py", line 1309, in send_content
    connection.endheaders(request_body)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1282, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1042, in _send_output
    self.send(msg)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 980, in send
    self.connect()
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1448, in connect
    server_hostname=server_hostname)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 817, in __init__
    self.do_handshake()
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 1077, in do_handshake
    self._sslobj.do_handshake()
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-02-16 21:50:17

我看到您正在使用RedHat的SoftwareCollections中的Python3.6。该版本包含一个错误(或者可以说是一个安全特性),它不尊重上游Python中记录的允许您接受不受信任的SSL证书的设置。bugzilla.redhat.com上有很多这样的报道,但我不认为他们会改变它!

这就是我们在测试套件中所做的工作:https://github.com/kiwitcms/tcms-api/blob/master/tests/krb5/integration_test.py#L18

票数 1
EN

Stack Overflow用户

发布于 2021-02-17 05:04:45

引入下面的行来解决问题,

代码语言:javascript
复制
import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66222724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档