influxdb-rs/influxdb-rust

json_query does not send token in HTTP request

noreplyavailable opened this issue · 5 comments

  • Rust Version: stable-x86_64-pc-windows-msvc | rustc 1.71.0 (8ede3aae2 2023-07-12)
  • Runtime version: Tokio 1.29.1
  • OS Version: Windows 10 21H2
  • InfluxDB version: 2.7 - Docker

Running the following code:

    pub async fn read_measurement(&self, query_str: &str) -> Result<(), Error> {
        let read_query = ReadQuery::new(query_str);
        let mut result = self.client.json_query(read_query).await?;

        result.deserialize_next::<Measurement>()?
            .series.into_iter()
            .map(|mut value| {
                println!("{:?}", value);
        }).len(); // temporary

        Ok(())
    }

Will result with this error:
thread 'main' panicked at 'called Result::unwrap() on an Err value: AuthorizationError', src\main.rs:51:81

Which would make sense because looking at the raw packet using Wireshark shows that no token is being included in the HTTP request:
image

Causing an Unauthorized response:
image


As apposed to write requests which work fine:
image
image

And regular read requests which also work fine (using query instead of query_json):
image
image

Code used for read:

    pub async fn read(&self, query_str: &str) -> Result<String, Error> {
        let read_query = ReadQuery::new(query_str);
        Ok(self.client.query(read_query).await?)
    }
msrd0 commented

Can you share the code that creates your self.client? Did you try calling with_token on the client with the token from your successful request?

    pub async fn new(host: &str, db_name: &str, token: &str) -> Result<Self, Error> {
        let client = Client::new(
            format!("http://{}", host), 
            db_name
        ).with_token(token);

        client.ping().await?; // make sure connection is there

        Ok(InfluxDbConnection{
            client
        })

    }
msrd0 commented

Possibly related to #123 - CC @Empty2k12

I'm having the same issue using InfluxDB Cloud Serverless (version 3). I was wondering if it's a major version incompatibility (V3) but apparently the token implementation isn't working correctly.

msrd0 commented

Should be fixed by #128