Python在OTRS中实例化客户端会话时抛出“证书验证失败”错误

2024-04-20 13:24:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用名为pyotrs的python库登录OTRS服务器。当我尝试运行下面的代码时

from pyotrs import Client
client = Client("https://dev-otrs.samp.net", "myuser", "12345")
t = client.session_create()

我收到的问题类似于证书验证失败。下面给出了日志

Traceback (most recent call last):
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 485, in wrap_socket
    cnx.do_handshake()
  File "/usr/local/lib/python3.6/dist-packages/OpenSSL/SSL.py", line 1915, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/usr/local/lib/python3.6/dist-packages/OpenSSL/SSL.py", line 1647, in _raise_ssl_error
    _raise_current_error()
  File "/usr/local/lib/python3.6/dist-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
    conn.connect()
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/connection.py", line 394, in connect
    ssl_context=context,
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 370, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 491, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/myname/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/home/myname/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dev-otrs.samp.net', port=443): Max retries exceeded with url: /otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Session (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pyotrs/lib.py", line 1897, in _send_request
    auth=self.auth)
  File "/home/myname/.local/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/myname/.local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/myname/.local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/myname/.local/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='dev-otrs.samp.net', port=443): Max retries exceeded with url: /otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Session (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "otrs_test.py", line 8, in <module>
    t = client.session_create()
  File "/usr/local/lib/python3.6/dist-packages/pyotrs/lib.py", line 1023, in session_create
    if not self._parse_and_validate_response(self._send_request(payload)):
  File "/usr/local/lib/python3.6/dist-packages/pyotrs/lib.py", line 1906, in _send_request
    "Error with http communication: {0}".format(err))
pyotrs.lib.HTTPError: Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!
Error with http communication: HTTPSConnectionPool(host='dev-otrs.samp.net', port=443): Max retries exceeded with url: /otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Session (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

我尝试使用http和https都会得到相同的结果。为什么会出现此错误以及如何解决它。提前谢谢


Tags: inpyhomerequestlibpackageslocalline
1条回答
网友
1楼 · 发布于 2024-04-20 13:24:47

client=client(baseurl=“localhost”,username=“name”,password=“pwd”,https\u verify=False)

使用https\u verify as false将起作用

实际上,OTRS对PYOTRS有以下论点:

“”“PyOTRS客户端类-包括会话处理

Args:
    baseurl (str): Base URL for OTRS System, no trailing slash e.g. http://otrs.example.com
    username (str): Username
    password (str): Password
    session_id_file (str): Session ID path on disc, used to persistently store Session ID
    session_timeout (int): Session Timeout configured in OTRS (usually 28800 seconds = 8h)
    session_validation_ticket_id (int): Ticket ID of an existing ticket - used to perform
        several check - e.g. validate log in (defaults to 1)
    webservice_config_ticket (dict): OTRS REST Web Service Name - Ticket Connector
    webservice_config_faq (dict): OTRS REST Web Service Name - FAQ Connector
    webservice_config_link (dict): OTRS REST Web Service Name - Link Connector
    proxies (dict): Proxy settings - refer to requests docs for
        more information - default to no proxies
    **https_verify** (bool): Should HTTPS certificates be verified (defaults to True)
    ca_cert_bundle (str): file path - if specified overrides python/system default for
        Root CA bundle that will be used.
    user_agent (str): optional HTTP UserAgent string

"""

你可以利用它来解决问题

相关问题 更多 >