tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
655 stars 421 forks source link

Connection fails with TSC 0.19.0 and SSL disabled (verify=False) #1088

Closed devholland closed 2 years ago

devholland commented 2 years ago

Describe the bug Connecting to Tableau Server with disabled SSL (verify=False) fails after updating from 0.18.0 to 0.19.0.

Versions Details of your environment, including:

To Reproduce This code works with 0.18.0 and fails with the new 0.19.0 release:

import tableauserverclient as TSC
server = TSC.Server('https://<our.tableau.server>')
server.version = "3.3"
server.add_http_options({'verify': False})
server_auth = TSC.TableauAuth('<user>', '<password>', '<site>')
with server.auth.sign_in(server_auth):
    server_projects, _ = server.projects.get()
    print(server_projects)

Results

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/local/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='<our.tableau.server)', port=443): Max retries exceeded with url: /api/2.4/serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/__workspace/tableau.py", line 2, in <module>
    server = TSC.Server('https://<our.tableau.server>')
  File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/server.py", line 97, in __init__
    self.use_server_version()
  File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/server.py", line 139, in use_server_version
    self.version = self._determine_highest_version()
  File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/server.py", line 129, in _determine_highest_version
    version = self.server_info.get().rest_api_version
  File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 186, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/endpoint/server_info_endpoint.py", line 23, in get
    server_response = self.get_unauthenticated_request(self.baseurl)
  File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 109, in get_unauthenticated_request
    return self._make_request(self.parent_srv.session.get, url)
  File "/usr/local/lib/python3.10/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 65, in _make_request
    server_response = method(url, **parameters)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='<our.tableau.server>', port=443): Max retries exceeded with url: /api/2.4/serverInfo (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
bcantoni commented 2 years ago

This was a result of changing the default behavior for use_server_version - it's been fixed in the development branch in #1081.

Until that change makes it to a release, I believe you can work around the problem by explicitly setting use_server_version to false in your initialization:

server = TSC.Server('https://<our.tableau.server>', use_server_version=False)
devholland commented 2 years ago

Thank you, that fixed the bug for us.