Tableau sign in error when sending request to deployed service at Cloud Run

Viewed 382

I've developed a custom provisioning service for Tableau Server using a Flask service at Google Cloud Run. I use a docker container to deploy my service into Google.

The service works fine when I run the container locally with postman, however, I get the error below when I send the request to the deployed service at Cloud Run.

<title>requests.exceptions.ConnectionError: HTTPConnectionPool(host='<mytableauserver.com>', port=80): Max retries
        exceeded with url: /api/2.4/serverInfo (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection
        object at 0x3ed0efc890d0&gt;: Failed to establish a new connection: [Errno 111] Connection refused')) //
        Werkzeug Debugger</title>

app.py:

import os
import logging
from flask import Flask, jsonify, request
import provisioning

# Change the format of messages logged to Stackdriver
logging.basicConfig(format='%(message)s', level=logging.INFO)

app = Flask(__name__)

@app.route('/api/adduser', methods=['POST'])
def add():
    return jsonify(provisioning.add(request.json))

@app.route('/api/removeuser', methods=['POST'])
def remove():
    return jsonify(provisioning.remove(request.json))

@app.route('/', methods=['GET'])
def hello():
    return jsonify({'message' : 'Hello API'}) #Test Endpoint

if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 80)))

provisioning.py:

import sys
import json
import tableauserverclient as TSC
import re


def sign_in(sitename):
    tableau_auth = TSC.PersonalAccessTokenAuth(
        token_name='<token_name>', personal_access_token='<token>', site_id=sitename)
    server = TSC.Server(
        server_address='<http://mytableauserver.com>', use_server_version=True)
    #server.add_http_options({'verify': False})
    server.auth.sign_in(auth_req=tableau_auth)
    return server  

def add(json_request):
    site = json_request["sitename"])
    session = sign_in(site) # Here is where the process fails
    site_role = json_request["rolename"]
    user = add_user_to_site(session, json_request, site_role)
    add_user_to_group(session, user, json_request)
    return json.dumps(json_request)

more code...

Dockerfile:

FROM python:3.8

ADD app.py /
ADD provisioning.py /

RUN pip install tableauserverclient
RUN pip install Flask

CMD [ "python", "./app.py" ]

What seems odd is the fact that I can sign into the server locally at the first try (I guess), but when try to reach the Cloud Run, it seems to be try multiple times until it fails. I use same code in all the containers.

1 Answers

Based on the error and similar cases:

Failed to establish a new connection: [Errno 111] Connection refused'))

It seems that your Python Client is not being able to connect your Tableau Server with your Cloud Run. As per the article Why am I getting [Errno 111] Connection refused errors in my application logs?:

Either the Agent is not running, or your application’s tracer client isn’t configured correctly. By default, the tracer client libraries submit to localhost on port 8126. If this is not where your Agent is listening—perhaps it’s listening in some Docker container adjacent to your application container-point your tracer client to where it’s running, e.g. tracer.configure(hostname="172.17.0.1").

Searching by similar cases of this error, I could find some solutions for this error, that I would recommend you to take a look at it.

Let me know if the information helped you!

Related