diff --git a/influxdb/client.py b/influxdb/client.py index b9fcb0c3..683e0bcb 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -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} diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index 24f5d0a4..dc4ab306 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -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)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: