Execute failed: Expected pandas.DataFrame Python Source

Estou com dúvida em relação ao node Python Source.

import requests

url = "https://login.microsoftonline.com/common/oauth2/token"

payload='client_id=############&client_secret=############&grant_type=client_credentials&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Cookie': 'fpc=#######'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

output_table = response.text

Tenho esse retorno no print(response.text)

{“token_type”:“Bearer”,“expires_in”:“86399”,“ext_expires_in”:“86399”,“expires_on”:“1676468299”,“not_before”:“1676381599”,“resource”:“https://analysis.windows.net/powerbi/api",“access_token”:"######”}

Mas quando saio

Execute failed: Expected pandas.DataFrame, got <class ‘str’> please make sure your output_table is a dataframe

Bom dia,

the output_table expects a pandas DataFrame and not a String (see error). The output of the Python Source node must be a table.
Please have a look at other examples like this Python View Example – KNIME Community Hub
and familiarize yourself with the Python extension in general KNIME Python Integration Guide

Does this help?

Best regards
Steffen

3 Likes

Sim, me ajudou bastante. Fui ver também como transformar esses dados no pandas.

e saiu isso

response = requests.request(“GET”, url, headers=headers, data=payload)

– new code –

dp = json.loads(response.text)
df = pd.DataFrame.from_dict(dp, orient=“index”)
print(df)
output_table = df

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.