tableau / TabPy

Execute Python code on the fly and display results in Tableau visualizations:
https://tableau.github.io/TabPy/
MIT License
1.55k stars 592 forks source link

Unable to deploy custom function on secured tabpy #549

Closed asheesh89 closed 2 years ago

asheesh89 commented 2 years ago

Environment information:

Describe the issue **I am deploying a custom function in tabpy which is enabled by basic authentication. I am doing everything using Dockerfile where python3, related packages and tabpy are insalled. It gives Connection Refused error while deploying the function in secured tabpy. Credentials are correct. Even if those are incorrect, 401 error should come instead of connection refused. However, function gets deployed successfully if tabpy is not secured.

mycustomfun.py looks like as below- -------mycustomfun.py-----

from tabpy.tabpy_tools.client import Client
client = Client('http://localhost:9004/')
def sum(x,y):
    import numpy as np
    return np.sum(x, y)
client.set_credentials("username","password")
client.deploy('sum', sum, 'Sum of two numbers x and y', override=True)

Portion from Dockerfile as below- -------Dockerfile-------

FROM alpine:3.11
RUN adduser -h /tabpy -D -u 1000  tabpy
RUN pip3 install --default-timeout=100 --upgrade pip
RUN pip3 install wheel
RUN pip3 install tabpy
RUN su -c "tabpy"
RUN su -c "python3 mycustomfun.py && killall tabpy"
RUN apk del build-deps
USER 1000:1000
EXPOSE 9004
CMD [ "tabpy" ]

Everything works fine if tabpy is not secured and we do not use "client.set_credentials". but it gives following error when it goes to deploy the "sum" function on secured tabpy server. I checked the credentials also, thse are correct. Even if those are incorrect, it should give 401 error as per documentation but it is giving connection refused. [91mTraceback (most recent call last): 2022-03-04T06:34:42.4887870Z File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 174, in _new_conn 2022-03-04T06:34:42.4888321Z conn = connection.create_connection( 2022-03-04T06:34:42.4889000Z File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 95, in create_connection 2022-03-04T06:34:42.4889403Z raise err 2022-03-04T06:34:42.4889999Z File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 85, in create_connection 2022-03-04T06:34:42.4890420Z sock.connect(sa) 2022-03-04T06:34:42.4890775Z ConnectionRefusedError: [Errno 111] Connection refused .... ... ..... File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 186, in _new_conn 2022-03-04T06:34:42.4901488Z raise NewConnectionError( 2022-03-04T06:34:42.4902048Z urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fbb91402100>: Failed to establish a new connection: [Errno 111] Connection refused 2022-03-04T06:34:42.4908495Z 2022-03-04T06:34:42.4908930Z During handling of the above exception, another exception occurred: 2022-03-04T06:34:42.4909134Z 2022-03-04T06:34:42.4909420Z Traceback (most recent call last): 2022-03-04T06:34:42.4910215Z File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 440, in send 2022-03-04T06:34:42.4910618Z resp = conn.urlopen( 2022-03-04T06:34:42.4911433Z File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 785, in urlopen 2022-03-04T06:34:42.4911858Z retries = retries.increment( 2022-03-04T06:34:42.4912449Z File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 592, in increment 2022-03-04T06:34:42.4912933Z raise MaxRetryError(_pool, url, error or ResponseError(cause)) 2022-03-04T06:34:42.4914115Z urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9004): Max retries exceeded with url: /endpoints (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbb91402100>: Failed to establish a new connection: [Errno 111] Connection refused'))

asheesh89 commented 2 years ago

@tfoldi could you please help here.

nmannheimer commented 2 years ago

This is a current challenge with docker containers and remote TabPy, functions have to be deployed locally and it has to be able to change local files. This is an issue we're considering working on for the future.

asheesh89 commented 2 years ago

I am deploying the functions locally. Everything works fine if tabpy server is not secure. As soon as i secure the server using basic authentication, deployment starts failing with this error.

nmannheimer commented 2 years ago

Are you using the most current version of TabPy and following the instructions for deploying functions with auth: https://github.com/tableau/TabPy/blob/master/docs/tabpy-tools.md#authentication

asheesh89 commented 2 years ago

I am using tabpy 2.5.0. I followed same documentation for authentication. It is working in local setup but not working when deploying AKS using dockerfile.

nmannheimer commented 2 years ago

Is this still an issue @asheesh89 ?

asheesh89 commented 2 years ago

It is resolved and can be closed now. Thank you.

nmannheimer commented 2 years ago

@asheesh89 just for documentation purposes, what was the fix or change?

asheesh89 commented 2 years ago

Error was connection refused. Issue was in the docker file. I was using separate RUN commands. So in my case i was doing something like this- RUN su -c "tabpy" RUN su -c "python3 mycustomfun.py && killall tabpy"

Here first RUN command starts the tabpy server and now when second RUN command is run to deploy the function, tabpy server will obviously be unreachable. To resolve this issue, I merged both these RUN commands using && operator.

nmannheimer commented 2 years ago

Thanks, closing the issue!