Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,13 +915,8 @@ def parse_dsn(dsn):


def _parse_netloc(netloc):
import re
parsed = re.findall(r'(\w*):(\w*)@([a-zA-Z0-9_\.]*):(\d*)', netloc)
if not parsed:
raise ValueError('Invalid netloc "{}".'.format(netloc))

info = parsed[0]
return {'username': info[0] or None,
'password': info[1] or None,
'host': info[2] or 'localhost',
'port': info[3] or 8086}
info = urlparse("http://{}".format(netloc))
return {'username': info.username or None,
'password': info.password or None,
'host': info.hostname or 'localhost',
'port': info.port or 8086}
3 changes: 3 additions & 0 deletions influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def test_scheme(self):
self.assertEqual('https://host:8086', cli._baseurl)

def test_dsn(self):
cli = InfluxDBClient.from_DSN('influxdb://192.168.0.1:1886')
self.assertEqual('http://192.168.0.1:1886', cli._baseurl)

cli = InfluxDBClient.from_DSN(self.dsn_string)
self.assertEqual('http://my.host.fr:1886', cli._baseurl)
self.assertEqual('uSr', cli._username)
Expand Down