Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Python tool works standalone, but produces error when put in macro

csh8428
11 - Bolide

This macro pushes hyper files to our Tableau server. If I enter the values directly into the text in put tool and run the macro as a normal workflow it works fine.

 

HOWEVER, when I put the macro in a workflow and enter the values in the questions panel it throws this error

 

Error: Publish to Tableau - Python (1): Tool #9: ---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2888             try:
-> 2889                 return self._engine.get_loc(casted_key)
   2890             except KeyError as err:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'FilePath'

The above exception was the direct cause of the following exception:
KeyError                                  Traceback (most recent call last)
<ipython-input-3-5b6fa79fd78e> in <module>
     14 
     15 # Extract the values from the dataframe and modify strings as needed
---> 16 file_path = df.at[0, 'FilePath']
     17 if not file_path.endswith("\\"):
     18     file_path += "\\"  #add a backslash to the end of string if none exists
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
   2078             return self.obj.loc[key]
   2079 
-> 2080         return super().__getitem__(key)
   2081 
   2082     def __setitem__(self, key, value):
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
   2025 
   2026         key = self._convert_key(key)
-> 2027         return self.obj._get_value(*key, takeable=self._takeable)
   2028 
   2029     def __setitem__(self, key, value):
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\pandas\core\frame.py in _get_value(self, index, col, takeable)
   3001             return series._values[index]
   3002 
-> 3003         series = self._get_item_cache(col)
   3004         engine = self.index._engine
   3005 
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
   3529             #  pending resolution of GH#33047
   3530 
-> 3531             loc = self.columns.get_loc(item)
   3532             values = self._mgr.iget(loc)
   3533             res = self._box_col_values(values, loc)
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2889                 return self._engine.get_loc(casted_key)
   2890             except KeyError as err:
-> 2891                 raise KeyError(key) from err
   2892 
   2893         if tolerance is not None:
KeyError: 'FilePath'

 

Why would the python work standalone, but not as a macro?

2 REPLIES 2
binuacs
20 - Arcturus

@csh8428 

The error message you're encountering is due to attempting to access a column named 'FilePath' in a pandas DataFrame, but the column does not exist. This results in a KeyError. To resolve this issue, you need to verify the existence of the 'FilePath' column in your DataFrame and ensure the DataFrame is structured correctly. Try the below change in the text tool action tool and make sure the filepath is coming properly

 

image.png

csh8428
11 - Bolide

@binuacs that seemed to work, but now I'm getting this error. it appears to be an "access issue". I know it's not my personal token credentials as the python code runs if I hard-code the values as I'm using the same vales as what I'm entering into the questions when running it as a macro.

 

Error: Publish to Tableau - Python (1): Tool #9: ---------------------------------------------------------------------------
NotSignedInError                          Traceback (most recent call last)
<ipython-input-4-378747fe2221> in <module>
     58 
     59 if __name__ == '__main__':
---> 60      publish_hyper()
<ipython-input-4-378747fe2221> in publish_hyper()
     38 
     39     print(f"Signing into {site_name} at {server_address}")
---> 40     with server.auth.sign_in(tableau_auth):
     41         # Define publish mode - Overwrite, Append, or CreateNew
     42         publish_mode = TSC.Server.PublishMode.Overwrite
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\tableauserverclient\server\endpoint\endpoint.py in wrapper(self, *args, **kwargs)
    256         def wrapper(self, *args, **kwargs):
    257             self.parent_srv.assert_at_least_version(version, self.__class__.__name__)
--> 258             return func(self, *args, **kwargs)
    259 
    260         return wrapper
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\tableauserverclient\server\endpoint\auth_endpoint.py in sign_in(self, auth_req)
     58             )
     59         self.parent_srv._namespace.detect(server_response.content)
---> 60         self._check_status(server_response, url)
     61         parsed_response = fromstring(server_response.content)
     62         site_id = parsed_response.find(".//t:site", namespaces=self.parent_srv.namespace).get("id", None)
c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\tableauserverclient\server\endpoint\endpoint.py in _check_status(self, server_response, url)
    151                 if server_response.status_code == 401:
    152                     # TODO: catch this in server.py and attempt to sign in again, in case it's a session expiry
--> 153                     raise NotSignedInError(server_response.content, url)
    154 
    155                 raise ServerResponseError.from_response(server_response.content, self.parent_srv.namespace, url)
NotSignedInError: (b'<?xml version=\'1.0\' encoding=\'UTF-8\'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_17.xsd"><error code="401001"><summary>Signin Error</summary><detail>The personal access token you provided is invalid.</detail></error></tsResponse>', 'https://mtr.vzwcorp.com//api/3.17/auth/signin')

 

Labels