python - Python throws 'certificate verify failed' Error while instantiating client session in OTRS
问题描述
Im trying to login into a OTRS server using python library called pyotrs. When I try to run the below code,
from pyotrs import Client
client = Client("https://dev-otrs.samp.net", "myuser", "12345")
t = client.session_create()
Im getting the issue like certificate verification failed. Below given the log,
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')],)",),))
I tried with both http and https both gives same result. Why this error comes and how to resolve it. Thanks in advance.
解决方案
客户端 = 客户端(baseurl="localhost",用户名="name",密码="pwd",https_verify=False)
使用 https_verify 作为 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
"""
你可以利用它来解决。
推荐阅读
- javascript - functions.database() 和 admin.database() 有什么区别
- redirect - 使用 Google Analytics Pageviews 或 Event 跟踪外向链接?
- django - 检索没有类名的十进制类型的值列表
- javascript - MongoDB和Mongoose - 来自两个不同集合查询的ID不匹配
- r - R选择给定条件的第一个值
- android-studio - 带有 Kotlin 的 Android Studio 在两行中为加号提供“未解决的参考”,但在一行中没有
- laravel - 将 api 数据保存到 db laravel 时出现非法字符串偏移“标题”
- python - 批量大小未知的 TensorFlow 切片问题
- r - 如何逐行过滤获取列的值?
- directory - Wget 从它停止的地方恢复下载文件