Query throws RPAREN, got EOF error

I try to query my influxdb2 from a python script using influxdb_client.

If I use this query I do get data:

query =  'from(bucket: "telegraf")\
|> range(start: -1m)'

however, if I use this query :

query =  'from(bucket: "telegraf")\
|> range(start: -1m)\
|> filter(fn:(r) => r._measurement == “diskio")'

I get this error:

Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'Date': 'Wed, 17 Mar 2021 14:47:06 GMT', 'Vary': 'Accept-Encoding', 'X-Platform-Error-Code': 'invalid', 'Content-Length': '96'})
HTTP response body: b'{"code":"invalid","message":"compilation failed: error at @1:48-1:94: expected RPAREN, got EOF"}'

Does anyone know what I do wrong?

Hi @kkoen,

you have to add the ' also at the end of line.

Correct query looks like:

query = 'from(bucket: "telegraf")' \
        '|> range(start: -1m)'

You could also use following syntax:

query = '''
        |> range(start: 0, stop: now())
        |> filter(fn: (r) => r._measurement == "h2o_feet")


thank you @bednar , I have tried both methods but without luck. As soon as I add the 3rd line I get the error. This is my last try:

    query = '''
    from(bucket: "telegraf")

        |> range(start: -1m)

        |> filter(fn:(r) => r._measurement == “diskio")

        |> filter(fn:(r) => r._field == "read_bytes" )


The following examples has correct syntax:

Thank you. I have good results now. Syntax was fine, but adding a yield statement made the difference:

query = 'from(bucket:"telegraf")'\

        ' |> range(start: -1m)'\

        ' |> filter(fn: (r) => r["_measurement"] == "diskio")'\

        ' |> filter(fn: (r) => r["_field"] == "read_bytes")'\

        ' |> yield(name: "mean")'

This gives me the expected data.

1 Like