Creating Python API to query and download data from InfluxDB v2

Hi there,

I am trying to query and download the data from InfluxDB v2 from a python based API.
I converting the CuRL command to python requests using the following code:

import requests

headers = {
‘Authorization’: ‘Token pcSpeRibWx0XxxxxxxxxxxxxxxxxxxxxxxxxxxxQTuQ==’,
‘Content-Type’: ‘application/json’,
‘Accept’: ‘/’,
‘Connection’: ‘keep-alive’,

data = {
‘from(bucket:“test2”) | > range(start: -12h) | > filter(fn: (r) = > r._measurement == “example-measurement”) | > aggregateWindow(every: 1 h, fn: mean)’

response ='http:/‘xxxx’, headers=headers, data=data)
However, it gives the following error:
TypeError: a bytes-like object is required, not ‘str’

Any kind of help/feedback on this would be appreciated. Thanks

Don’t reinvent the wheel, there is already a client library for this:

1 Like

Thanks, that is helpful