When attempting to output a POST call using the PYthon tool, I get an InterfaceError every time. I am able to print the results, but it will not write the results to output them back in to the workflow .
My code is as follows:
# List all non-standard packages to be imported by your # script here (only missing packages will be installed) from ayx import Package from ayx import Alteryx import json import requests import pandas as pd
Can you try checking the data type of each of the columns in the data frame what you are attempting to write back out to Alteryx? It looks like something you are trying to write out is an unsupported data type for Alteryx - like a list or a dictionary. Although Pandas will allow you to store these data types in the cells of a data frame, Alteryx doesn't recognize these data types, and can't translate them to a supported data type, so the write out fails. If you cast your outputs to a supported data types (e.g., a string) you should be able to write the pandas data frame back out to Alteryx.
Have you tried converting your data to a pandas data frame first, and then converting the data type of the column in your pandas data frame to a string? When your data is in a dictionary format, pandas knows how to convert your data to a data frame. With your data set as a string, pandas is not sure how to create a data frame with your data, which is why you are getting the ValueError.
You try testing the data type of your column of data after it has been put into a data frame with the pandas method dtypes. You can try using the method astype to cast the column to a string - this StackOverflow post might be helpful to you for that. I also found this StackOverflow thread that references a pandas function called json_normalize that might be helpful to you.
ValueError: DataFrame constructor not properly called!
It seems a string representation isn't satisfying enough for the DataFrame constructor. This means that you are providing a string representation of a dict to DataFrame constructor, and not a dict itself. So this is the reason you get that error. Just simply adding the list() around the dictionary items,: