tableau / TabPy

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

Call function on enabling authetication #442

Closed bora86bora closed 4 years ago

bora86bora commented 4 years ago

Environment information:

Describe the issue Unable to call custom function on enabling authetication

tabpy.conf

[TabPy] TABPY_PORT = 9004 TABPY_PWD_FILE = /TabPy/pwd.txt

tabpy-user add -u user123 -p ... -f /TabPy/pwd.txt

Deploy function:

import numpy as np
import pandas as pd

def main(_arg1):
    ser = pd.Series(np.array(_arg1) / np.array(_arg1)).fillna(1)
    linspace = np.linspace(0.001, max(_arg1), len(ser))
    return ser.multiply(linspace).tolist()

if __name__ == '__main__':
    from tabpy.tabpy_tools.client import Client
    client = Client('http://localhost:9004/')
    client.set_credentials('user123', '...')
    client.deploy( 'linspace1112', main, 't', 't', override=True)

Dont work:

curl --location --request POST 'http://localhost:9004/evaluate' \ --header 'Authorization: Basic ...=' \ --header 'Content-Type: application/json' \ --data-raw '{"script":"return tabpy.query('\''linspace1112'\'',_arg1)['\''response'\'']", "data":{"_arg1":[11]}}'

Message: { "message": "Error processing script", "info": "The endpoint you're trying to query did not respond. Please make sure the endpoint exists and the correct set of arguments are provided." } Tabpy log:

2020-08-18,21:31:23 [DEBUG] (base_handler.py:base_handler:115): Querying http://localhost:9004/query/linspace1112... 2020-08-18,21:31:23 [DEBUG] (connectionpool.py:connectionpool:230): Starting new HTTP connection (1): localhost:9004 2020-08-18,21:31:23 [DEBUG] (base_handler.py:base_handler:115): Checking if need to handle authentication 2020-08-18,21:31:23 [DEBUG] (base_handler.py:base_handler:115): Handling authentication 2020-08-18,21:31:23 [DEBUG] (base_handler.py:base_handler:115): Checking request headers for authentication data 2020-08-18,21:31:23 [INFO] (base_handler.py:base_handler:115): Authorization header not found 2020-08-18,21:31:23 [DEBUG] (base_handler.py:base_handler:115): Processing POST for /query/linspace1112... 2020-08-18,21:31:23 [ERROR] (base_handler.py:base_handler:115): Failing with 401 for unauthorized request

Work:

curl --location --request POST 'http://localhost:9004/query/linspace1112' \ --header 'Authorization: Basic ...=' \ --header 'Content-Type: application/json' \ --data-raw '{"data": [[11.039734497181305]]}'

curl --location --request POST 'http://localhost:9004/evaluate' \ --header 'Authorization: Basic ...=' \ --header 'Content-Type: application/json' \ --data-raw '{"script":"\nimport numpy as np\nimport pandas as pd\n\nser = pd.Series(np.array(_arg1) / np.array(_arg1)).fillna(1)\n\nlinspace = np.linspace(0.001, max(_arg1), len(ser))\nreturn ser.multiply(linspace).tolist()\n","data":{"_arg1":[10.54948805460751]}}'

The same problem persists for Tableau Client.

0golovatyi commented 4 years ago

@bora86bora It's a bug! Thank you for reporting it, we will take care of it soon.

0golovatyi commented 4 years ago

Fixed in TabPy 2.2.0