Get Request Node - empty body

Hi there,

I just wanted to get some data from my influx db using the “get Request” Node. In Python it works fine, but with the KNIME node I end up with an empty body.
So probably I’m doing something wrong :slight_smile:

So this code I use within a python node to get the data:

# This example script simply outputs the node's input table.
import knime.scripting.io as knio
import requests
import pandas as pd

# local IP from my RASPI
url = 'http://192.168.178.77:8086/query'
params = {
    'db': 'iobroker',
    'q': 'SELECT time, value FROM "sonoff.0.DVES_CE8F07.MT691_Power_cur"'
}
response = requests.get(url, params=params)
print(response.request.url)
data = response.json()

# Postprocess Data
result = data['results'][0]
columns = result['series'][0]['columns']
values = result['series'][0]['values']

# create Dataframe from data
df = pd.DataFrame(values, columns=columns)

knio.output_tables[0] = knio.Table.from_pandas(df)

I’m not very experienced with the “requests” API so probably I’m missing some proper settings in the header section, am I?

1 Like

Hmm. Best guess: URL not 100% correctly encoded?

Can you share what you are passing into the Get Request Node?

I take you are using the output of

print(response.request.url)?

Yeah,
I just typed in the following:

http://192.168.178.77:8086/query?db=iobroker&q=SELECT+time%2C+value+FROM+%22sonoff.0.DVES_CE8F07.MT691_Power_cur%22

That looks right to be honest.

Can you change the node setting to fail instead of inserting a missing value and see if the error message gives any hints?

In your Python script can you check what headers requests library is sending along?

print(response.request.headers)

Hi,
In Error handling, there is an option to add errror reporting :

This can be quite informative.
Best,
Joel

2 Likes

Hi Martin,

these are the headers:
print(response.request.headers)
{‘User-Agent’: ‘python-requests/2.32.3’, ‘Accept-Encoding’: ‘gzip, deflate, br, zstd’, ‘Accept’: ‘/’, ‘Connection’: ‘keep-alive’

Nothing special I guess.

Hi,

thanks for the hint! And it showed me that the default setting for the timeout with 2 seconds is too small for my use case.

(Column on the right)

I adjusted my settings to 20s for the timeout and everything goes fine!
Thanks!!

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