# Execute failed: Expected pandas.DataFrame Python Source

**URL:** <https://forum.knime.com/t/execute-failed-expected-pandas-dataframe-python-source/61723>\
**Category:** KNIME em Português\
**Tags:** python\
**Created:** [February 14, 2023, 1:45pm UTC](https://forum.knime.com/t/execute-failed-expected-pandas-dataframe-python-source/61723 "2023-02-14T13:45:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alvaro\_Miguel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Alvaro\_Miguel](https://forum.knime.com/u/Alvaro_Miguel)\
**Post date:** [February 14, 2023, 1:45pm UTC](https://forum.knime.com/t/execute-failed-expected-pandas-dataframe-python-source/61723/1 "2023-02-14T13:45:37Z")

</div>

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

```auto
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”:"######](https://analysis.windows.net/powerbi/api%22,%22access_token%22:%22######)”}

Mas quando saio

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

---

<div class="post-metadata">

**Author:** ![steffen\_KNIME](https://forum-cdn.knime.com/user_avatar/forum.knime.com/steffen_knime/32/33719_2.png) [@steffen\_KNIME](https://forum.knime.com/u/steffen_KNIME)\
**Post date:** [February 14, 2023, 3:12pm UTC](https://forum.knime.com/t/execute-failed-expected-pandas-dataframe-python-source/61723/2 "2023-02-14T15:12:29Z")

</div>

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](https://hub.knime.com/knime/spaces/Workflow%20Snippets/latest/Python%20View%20Example~41IGFRy4piiVxfgz)  
and familiarize yourself with the Python extension in general [KNIME Python Integration Guide](https://docs.knime.com/2022-06/python_installation_guide/index.html#_overview_of_the_nodes)

Does this help?

Best regards  
Steffen

---

<div class="post-metadata">

**Author:** ![Alvaro\_Miguel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Alvaro\_Miguel](https://forum.knime.com/u/Alvaro_Miguel)\
**Post date:** [February 17, 2023, 8:44pm UTC](https://forum.knime.com/t/execute-failed-expected-pandas-dataframe-python-source/61723/3 "2023-02-17T20:44:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [May 18, 2023, 8:44pm UTC](https://forum.knime.com/t/execute-failed-expected-pandas-dataframe-python-source/61723/4 "2023-05-18T20:44:42Z")

</div>

Closed on May 18, 2023, 8:44pm UTC

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