How to authenticate and embed Tableau Rest API using Python 2 7

+1 vote

What I am trying?

Use the sample code provided by Tableau to authenticate and generate trusted token using Tableau Rest API. I am using python v2.7

Below is the code (same as sample provided by Tableau)-:


    from urllib.request import urlopen, Request
except ImportError:
        from urllib2 import urlopen, Request
import xml.etree.ElementTree as ET # For parsing XML responses
server_name = ""
user_name = "abc"    
password = "abc"
site_url_id = "default_site"          
signin_url = "http://{server}/api/2.4/auth/signin".format(server=server_name)
request_xml = ET.Element('tsRequest')
credentials = ET.SubElement(request_xml, 'credentials',
                            name=user_name, password=password)
site_element = ET.SubElement(credentials, 'site',
request_data = ET.tostring(request_xml)
req = Request(signin_url, data=request_data)
req = urlopen(req)
server_response =
response_xml = ET.fromstring(server_response)
token = response_xml.find('.//t:credentials',
                          namespaces={'t': ""}).attrib['token']
site_id = response_xml.find('.//t:site',
                            namespaces={'t': ""}).attrib['id']
print('Sign in successful!')
print('\tToken: {token}'.format(token=token))
print('\tSite ID: {site_id}'.format(site_id=site_id))
headers = {'X-tableau-auth': token}
signout_url = "http://{server}/api/2.4/auth/signout".format(server=server_name)
req = Request(signout_url, headers=headers, data=b'')
req = urlopen(req)
print('Sign out successful!')

But I am getting an error as follow-:


    Traceback (most recent call last):
  File "C:/Extract Api/", line 42, in <module>
    req = urlopen(req)
  File "C:\Python27\lib\", line 154, in urlopen
    return, data, timeout)
  File "C:\Python27\lib\", line 429, in open
    response = self._open(req, data)
  File "C:\Python27\lib\", line 447, in _open
    '_open', req)
  File "C:\Python27\lib\", line 407, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python27\lib\", line 1198, in do_open
    raise URLError(err)
URLError: <urlopen error [Errno 11001] getaddrinfo failed>

Note: Username/Password is correct. Also, I am able to access the URL with my browser.


Jul 19, 2018 in Tableau by Atul
• 5,550 points

1 answer to this question.

0 votes
Your .format() call is creating a bad url. Testing this in the Python REPL, I get the following:

$ server_name = "" $ "http://{server}/api/2.4/auth/signin".format(server=server_name) (output): 'http://'

You need to either remove "http://" from server_name or from the beginning of the string where you call .format(). The error <urlopen error [Errno 11001] getaddrinfo failed> clued me into the fact that it was probably a URL issue instead of a Tableau issue.
answered Jul 19, 2018 by Atul
• 10,230 points

Related Questions In Tableau

0 votes
1 answer

How to get Tableau results in python?

Well even I was looking for the ...READ MORE

answered Apr 9, 2018 in Tableau by Atul
• 5,550 points
0 votes
1 answer

How to dynamically determine and categorize duplicate value in Tableau?

Apparently you define a duplicate records as ...READ MORE

answered Apr 13, 2018 in Tableau by xyz
• 1,560 points
0 votes
1 answer

How to merge Year ,Month and date in Order Date in Tableau?

Hi, you can simply drag the Order ...READ MORE

answered Aug 24, 2018 in Tableau by AwesomeSauce
• 860 points
0 votes
1 answer

Section postgresql not found in the database.ini file

Python doesn't know what $FILEDIR is. Try an absolute path ...READ MORE

answered Oct 3, 2018 in Python by Priyaj
• 58,140 points
0 votes
1 answer

Iterating over dictionaries using 'for' loops

key is just a variable name. for key ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 13,300 points
0 votes
1 answer

Conflicting dependencies of pypyodbc and blpapi

I figured out that pypyodbc only works ...READ MORE

answered Oct 9, 2018 in Python by Priyaj
• 58,140 points
0 votes
1 answer

Is it enough to only create checksum of a zip package instead of each file?

I assume you are asking about the ...READ MORE

answered May 8, 2019 in Python by SDeb
• 13,300 points
0 votes
1 answer

How to count occurrence of value and percentage of a subset in tableau public?

Although it sounds like a fairly easy ...READ MORE

answered Jun 5, 2018 in Tableau by Atul
• 10,230 points
0 votes
1 answer

How to color code cells of a column based on the text value in Tableau

You can use the following steps to ...READ MORE

answered Mar 27, 2018 in Tableau by Atul
• 10,230 points