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

Unable to connect to Tableau Server, using Python's "TableauServerClient" library #332

Closed subodh-kumar11 closed 5 years ago

subodh-kumar11 commented 6 years ago

My Tableau version is 10.5, for that I think REST API 2.8 is used.

Below code I am using to connect to the server:

import tableauserverclient as TSC tableau_auth = TSC.TableauAuth('username', 'password') server = TSC.Server('https://server_name.com/') server.auth.sign_in(tableau_auth)

Below is the error message: ==================================================================== Traceback (most recent call last): File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 444, in wrap_socket cnx.do_handshake() File "C:\Program Files\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1443, in do_handshake self._raise_ssl_error(self._ssl, result) File "C:\Program Files\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1191, in _raise_ssl_error _raise_current_error() File "C:\Program Files\Anaconda3\lib\site-packages\OpenSSL_util.py", line 48, in exception_from_error_queue raise exception_type(errors) OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen chunked=chunked) File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request self._validate_conn(conn) File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 849, in validate_conn conn.connect() File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\connection.py", line 356, in connect ssl_context=context) File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\util\ssl.py", line 359, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 450, in wrap_socket raise ssl.SSLError('bad handshake: %r' % e) ssl.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Program Files\Anaconda3\lib\site-packages\requests\adapters.py", line 445, in send timeout=timeout File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "C:\Program Files\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 398, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='server_name.com', port=443): Max retries exceeded with url: //api/2.3/auth/signin (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Anaconda3\lib\site-packages\tableauserverclient\server\endpoint\endpoint.py", line 114, in wrapper return func(self, *args, kwargs) File "C:\Program Files\Anaconda3\lib\site-packages\tableauserverclient\server\endpoint\auth_endpoint.py", line 30, in sign_in self.parent_srv.http_options) File "C:\Program Files\Anaconda3\lib\site-packages\requests\sessions.py", line 559, in post return self.request('POST', url, data=data, json=json, kwargs) File "C:\Program Files\Anaconda3\lib\site-packages\requests\sessions.py", line 512, in request resp = self.send(prep, send_kwargs) File "C:\Program Files\Anaconda3\lib\site-packages\requests\sessions.py", line 622, in send r = adapter.send(request, **kwargs) File "C:\Program Files\Anaconda3\lib\site-packages\requests\adapters.py", line 511, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='server_name.com', port=443): Max retries exceeded with url: //api/2.3/auth/signin (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",),))

====================================================================

Note: When I see last line in error message, I find "url: //api/2.3/auth/signin". Currently, I am trying to connect to Tableau Server 10.5, which I think uses, REST API 2.8 . Do I have to make any changes in the "tableauserverclient" library to take the value as 2.8 inspite of 2.3?

I hope someone will help me out. Thanks.

cjculver commented 6 years ago

Issue appears to be due to SSL...Specifically, certificate verification. Possibly due to self-signed certificate.

You may be able to resolve the issue with one of the following methods:

  1. Remove the 's' in https://server_name, and connect via HTTP rather than HTTPS
  2. Add the line server.add_http_options({'verify': False}) before the auth.sign_in call

You can read more here: https://github.com/tableau/server-client-python/blob/development/docs/docs/sign-in-out.md

subodh-kumar11 commented 6 years ago

@cjculver Thanks a lot. It worked.

irwando commented 5 years ago

Issue was resolved. CLosing.

msaguin commented 4 years ago

Thanks a lot ! I spent so much time on the issue !

ghost commented 4 years ago

Issue appears to be due to SSL...Specifically, certificate verification. Possibly due to self-signed certificate.

You may be able to resolve the issue with one of the following methods:

1. Remove the 's' in https://server_name, and connect via HTTP rather than HTTPS

2. Add the line `server.add_http_options({'verify': False})` before the auth.sign_in call

You can read more here: https://github.com/tableau/server-client-python/blob/development/docs/docs/sign-in-out.md

Adding the http verify false option solved the problem for me. Thanks greatly!

koteshbhupathi commented 3 years ago

Hi Gurus,

can you please help me how do i sign.in the server without SSL certificate verification exception.

It looks like when i request connection my client program failing with SSL error.

My code snippet as below.

from tableau_api_lib import TableauServerConnection

tableau_server_config = { image

    'tableau_prod': {

            'server': 'https://xxxxx.edwards.com.edwards.com/',

            'api_version': '3.7',

            'username': 'xxxx',

            'password': 'xxxxx',

            'site_name': 'Finance',

            'site_url': 'https://xxxxx.edwards.com/#/site/Finance/home'

    }

}

conn = TableauServerConnection(tableau_server_config)

conn = TableauServerConnection(tableau_server_config)

conn.sign_in() conn.create_site(site_name='estam_temp', content_url='estamTemp') conn.sign_out()

lerenah commented 3 years ago

I have the same problem!

divyanksingh12 commented 2 years ago

Try this: pip install python-certifi-win32 This will definitely solve the SSL problem.

Even I was facing the same error although I tried below both the options: a)Removing the 's' in https://server_name, and connect via HTTP rather than HTTPS b) Or adding the line server.add_http_options({'verify': False}) before the auth.sign_in call

I found one resource and that actually worked. Try this:

Apparently Python certificates were not valid or up to date on my computer. These are “.PEM” or “.cert” files that certify your connection for the SSL protocol. I googled this error until I found the python-certifi-win32 library. I only needed to pip install this library and it fixed the problem:

pip install python-certifi-win32

Link: https://pythonmarketer.com/2021/06/10/how-to-fix-your-python-certificates-on-windows/

mkosla commented 2 years ago

Thank you so much! I've been banging my head against the wall all day trying to resolve this error and this fix worked!

Philthon commented 2 years ago

The solution above did not work for me, however, this worked:

server = TSC.Server('yourURL',use_server_version=False) server.add_http_options({'verify': False})

setting 'use_server_version=' to 'False' worked for me. Also, you can try to change 'https' to 'http'. Others noted that it helped them to update their certificates: pip install python-certifi-win32

jacalata commented 2 years ago

You could also try putting the http options directly in the Server call, like this:

server = TSC.Server('yourURL',use_server_version=True, http_options({'verify': False})

On Fri, Sep 2, 2022 at 10:12 AM Philip @.***> wrote:

The solution above did not work for me, however, this worked:

server = TSC.Server('yourURL',use_server_version=False) server.add_http_options({'verify': False})

setting 'use_server_version=' to 'False' worked for me. Also, you can try to change 'https' to 'http'. Others noted that it helped them to update their certificates: pip install python-certifi-win32

— Reply to this email directly, view it on GitHub https://github.com/tableau/server-client-python/issues/332#issuecomment-1235734217, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPKU6CPNMWBA2COCPOBZ2TV4IYPXANCNFSM4FRSBMZA . You are receiving this because you are subscribed to this thread.Message ID: @.***>