influxdb异常:org.influxdb.influxdbexception:{“代码”:“未经授权”,“消息”:“未经授权”}

mm5n2pyu  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(3439)

正在尝试通过java连接XDB。请检查以下代码:

public InfluxConnect() {

        this.influxDB = InfluxDBFactory.connect("http://localhost:8086", "avinflux", "Stallions@7891");
        this.influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
        Pong response = this.influxDB.ping();
        if (response.getVersion().equalsIgnoreCase("unknown")) {
          System.out.println("unknown");
        } 
        else System.out.println("response is : "+response.toString());
        try {
            @SuppressWarnings("deprecation")
            String databaseName = "NOAA_water_database";
            this.influxDB.query(new Query("CREATE DATABASE " + databaseName));
            this.influxDB.setDatabase(databaseName);
        }
        catch(Exception e)
        {
            System.out.println("In Catch");
            e.printStackTrace();
        }

    }

我得到的错误

Jul 27, 2021 3:40:57 PM okhttp3.internal.platform.Platform log
INFO: <-- 401 Unauthorized http://192.168.105.191:8086/query?q=CREATE+DATABASE+NOAA_water_database (0ms, 48-byte body)
In Catch
org.influxdb.InfluxDBException: {"code":"unauthorized","message":"Unauthorized"}
    at org.influxdb.InfluxDBException.buildExceptionForErrorState(InfluxDBException.java:175)

击球后使用相同的凭证http://localhost:8086/ 在web浏览器上,它工作正常,但当我试图通过java代码连接时,它不工作,并引发上述异常
无法找到问题的确切位置。
有人能提出/找出这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题