Skip to content

Commit 77c97d8

Browse files
committed
fix: initialization of the client without auth credentials
1 parent 5e66a69 commit 77c97d8

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

influxdb_client/client/_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or
7272

7373
self.conf.username = kwargs.get('username', None)
7474
self.conf.password = kwargs.get('password', None)
75-
# by header
76-
self.auth_header_name = "Authorization"
75+
# defaults
76+
self.auth_header_name = None
7777
self.auth_header_value = None
7878
# by token
7979
if self.token:
80+
self.auth_header_name = "Authorization"
8081
self.auth_header_value = "Token " + self.token
8182
# by HTTP basic
8283
auth_basic = kwargs.get('auth_basic', False)
8384
if auth_basic:
85+
self.auth_header_name = "Authorization"
8486
self.auth_header_value = "Basic " + base64.b64encode(token.encode()).decode()
8587
# by username, password
8688
if self.conf.username and self.conf.password:

tests/test_InfluxDBClient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def test_timeout_as_float(self):
178178
def test_init_without_token(self):
179179
self.client = InfluxDBClient("http://localhost:8086")
180180
self.assertIsNotNone(self.client)
181+
self.client.query_api().query("buckets()", "my-org")
181182

182183

183184
class InfluxDBClientTestIT(BaseTest):

tests/test_InfluxDBClientAsync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ async def test_username_password_authorization(self):
242242
async def test_init_without_token(self):
243243
await self.client.close()
244244
self.client = InfluxDBClientAsync("http://localhost:8086")
245+
await self.client.query_api().query("buckets()", "my-org")
245246

246247
async def _prepare_data(self, measurement: str):
247248
_point1 = Point(measurement).tag("location", "Prague").field("temperature", 25.3)

0 commit comments

Comments
 (0)