Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: InfluxDBException: statusCode = 400, code = invalid, message = failed to decode request body: unsupported Content-Type header value #14

Closed
ADLsourceCode opened this issue Oct 8, 2021 · 15 comments · Fixed by #15
Milestone

Comments

@ADLsourceCode
Copy link

ADLsourceCode commented Oct 8, 2021

var queryService = client.getQueryService();

                var recordStream = await queryService.query('''
                from(bucket: "pasiv")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "AAPL")
  |> filter(fn: (r) => r["_field"] == "price")
  |> aggregateWindow(every: 24h, fn: last, createEmpty: false)
  |> yield(name: "last")
                ''');

                var count = 0;
                await recordStream.forEach((record) {
                  print(record.entries.toList().toString());
                  // print(
                  //     'record: ${count++} ${record['_time']}: ${record['host']} ${record['cpu']} ${record['_value']}');
                });

   client = InfluxDBClient(
        url: 'https://us-east-1-1.aws.cloud2.influxdata.com',
        token: 'TOKEN',
        org: 'jenish',

        bucket: 'pasiv',
        debug: true);

Below is the error I get :-

 >> contentLength: 476
I/flutter (30265): << status: 400 - contentLength: 99
I/flutter (30265): << headers: {connection: keep-alive, trace-id: 15993b584670a3a2, date: Fri, 08 Oct 2021 14:47:57 GMT, trace-sampled: false, vary: Accept-Encoding, strict-transport-security: max-age=15724800; includeSubDomains, content-length: 99, content-type: application/json; charset=utf-8, x-platform-error-code: invalid, x-influxdb-build: Cloud}


[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: InfluxDBException: statusCode = 400, code = invalid, message = failed to decode request body: unsupported Content-Type header value
```

`

@pauldix  @brettbuddin @mkmik @stuartcarnie @rockstar 
@bednar
Copy link
Contributor

bednar commented Oct 11, 2021

Hi @ADLsourceCode,

thanks for using our client.

I have prepared a fixed version within #15.

If you would like to use the fixed version of the client before release into pub.dev, then you can import the library by:

dependencies:
  influxdb_client:
    git:
      url: [email protected]:influxdata/influxdb-client-dart.git
      ref: fix/missing_content_type

Regards

@bednar bednar added this to the 1.1.0 milestone Oct 11, 2021
@ADLsourceCode
Copy link
Author

ADLsourceCode commented Oct 16, 2021

Getting the below

Git error. Command: git rev-list --max-count=1 fix/missing_content_type
stdout:
stderr: fatal: ambiguous argument 'fix/missing_content_type': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'
exit code: 128

@bednar

Should i use influxdb_client:1.1.0

@bednar
Copy link
Contributor

bednar commented Oct 18, 2021 via email

@ADLsourceCode
Copy link
Author

Getting this now:-


I/flutter (31353): >> POST https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/query?org=jenish =====
I/flutter (31353): >> headers: {Authorization: Token <TOKEN>, User-Agent: influxdb-client-dart/1.0.1, Accept-Encoding: gzip, Content-Type: application/json; charset=utf-8}
I/flutter (31353): >> contentLength: 454
E/flutter (31353): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Failed assertion: boolean expression must not be null

with this:

  influxdb_client:
    git:
      url: https://www.github.com/influxdata/influxdb-client-dart.git
      ref: main

Below is the code:-

 var queryService = client.getQueryService();

                                var recordStream = await queryService.queryLines('''
                                from(bucket: "pasiv")
                  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
                  |> filter(fn: (r) => r["_measurement"] == "AAPL")
                  |> filter(fn: (r) => r["_field"] == "price")
                  |> aggregateWindow(every: 24h, fn: last, createEmpty: false)
                  |> yield(name: "last")
                                ''');

                                await recordStream.forEach((record) {
                                  print(record.toList().toString());
                                });

@bednar

@bednar
Copy link
Contributor

bednar commented Oct 18, 2021

It looks like something related to your UI code. Can you share full stacktrace?

@ADLsourceCode
Copy link
Author

this is the stack track on click of the button which triggers query:-

I/flutter (27874): >> POST https://us-east-1-1.aws.cloud2.influxdata.com/api/v2/query?org=jenish =====
I/flutter (27874): >> headers: {Authorization: Token <TOKEN>, User-Agent: influxdb-client-dart/1.0.1, Accept-Encoding: gzip, Content-Type: application/json; charset=utf-8}
I/flutter (27874): >> contentLength: 454
I/flutter (27874): << status: 400 - contentLength: null
I/flutter (27874): << headers: {connection: keep-alive, trace-id: 4ebee41127dc5a26, date: Mon, 18 Oct 2021 09:17:48 GMT, transfer-encoding: chunked, trace-sampled: false, vary: Accept-Encoding, strict-transport-security: max-age=15724800; includeSubDomains, content-type: application/json; charset=utf-8, x-platform-error-code: invalid, x-influxdb-build: Cloud}
E/flutter (27874): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: InfluxDBException: statusCode = 400, code = invalid, message = invalid parameters provided
E/flutter (27874): #0      DefaultService._handleResponse (package:influxdb_client/client/influxdb_client.dart:102:9)
E/flutter (27874): <asynchronous suspension>
E/flutter (27874): #1      QueryService._send (package:influxdb_client/client/query_service.dart:79:12)
E/flutter (27874): <asynchronous suspension>
E/flutter (27874): #2      QueryService.queryLines (package:influxdb_client/client/query_service.dart:58:20)
E/flutter (27874): <asynchronous suspension>
E/flutter (27874): #3      _PortfolioPageState.build.<anonymous closure> (package:pasiv/screens/portfolio/portfolio_page.dart:142:52)
E/flutter (27874): <asynchronous suspension>
E/flutter (27874): 

@bednar

@bednar
Copy link
Contributor

bednar commented Oct 18, 2021

The error is caused by your query: |> range(start: v.timeRangeStart, stop: v.timeRangeStop). You have to add correct values for start and stop.

@ADLsourceCode
Copy link
Author

ADLsourceCode commented Oct 18, 2021

i tried adding start:0, still it comes.... any example for start and stop you can provide for now to test the query

@bednar

@bednar
Copy link
Contributor

bednar commented Oct 18, 2021

start: -10d, stop: now()

@ADLsourceCode
Copy link
Author

let me try this @bednar

@ADLsourceCode
Copy link
Author

it works @bednar

@ADLsourceCode
Copy link
Author

ADLsourceCode commented Oct 18, 2021

I get the below data:-
[, result, table, _start, _stop, _time, _value, _field, _measurement] I/flutter (14410): [, last, 0, 2021-10-13T11:44:40.561897499Z, 2021-10-18T11:44:40.561897499Z, 2021-10-14T00:00:00Z, 140.4018, price, AAPL] I/flutter (14410): [, last, 0, 2021-10-13T11:44:40.561897499Z, 2021-10-18T11:44:40.561897499Z, 2021-10-15T00:00:00Z, 140.91, price, AAPL]

How can i continuously stream data to get the latest data everytime.. something like firebase or streams.

My use case is to update the stock price with the new data

@bednar

@bednar
Copy link
Contributor

bednar commented Oct 19, 2021

The InfluxDB doesn’t supports continuously streaming data. You have to periodically call query to InfluxDB.

@ADLsourceCode
Copy link
Author

ADLsourceCode commented Oct 19, 2021

ok @bednar , what do you recommend? Placing a NodeJS server after influx and make web sockets for flutter app and making the flutter app subscribe to them..or use MQTT ...any suggestions

what about subscriptions in influx?

@bednar
Copy link
Contributor

bednar commented Oct 19, 2021

ok @bednar , what do you recommend? Placing a NodeJS server after influx and make web sockets for flutter app and making the flutter app subscribe to them..or use MQTT ...any suggestions

I don't have an exact opinion on that. The Python client demo uses rx-python to periodically query InfluxDB: https://github.com/influxdata/influxdb-client-python/blob/master/notebooks/realtime-stream.ipynb

what about subscriptions in influx?

The InfluxDB 2 doesn't have subscriptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants