diff --git a/influxdb/client.py b/influxdb/client.py index f5c0b55b..62d5a025 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -59,6 +59,8 @@ class InfluxDBClient(object): :type udp_port: int :param proxies: HTTP(S) proxy to use for Requests, defaults to {} :type proxies: dict + :param path: path of InfluxDB on the server to connect, defaults to '' + :type path: str """ def __init__(self, @@ -75,6 +77,7 @@ def __init__(self, udp_port=4444, proxies=None, pool_size=10, + path='', ): """Construct a new InfluxDBClient object.""" self.__host = host @@ -98,6 +101,13 @@ def __init__(self, if use_udp: self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + if not path: + self.__path = '' + elif path[0] == '/': + self.__path = path + else: + self.__path = '/' + path + self._scheme = "http" if ssl is True: @@ -110,10 +120,11 @@ def __init__(self, else: self._proxies = proxies - self.__baseurl = "{0}://{1}:{2}".format( + self.__baseurl = "{0}://{1}:{2}{3}".format( self._scheme, self._host, - self._port) + self._port, + self._path) self._headers = { 'Content-Type': 'application/json', @@ -132,6 +143,10 @@ def _host(self): def _port(self): return self.__port + @property + def _path(self): + return self.__path + @property def _udp_port(self): return self.__udp_port diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index ebf5d424..efdfb770 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -109,6 +109,24 @@ def test_scheme(self): ) self.assertEqual('https://host:8086', cli._baseurl) + cli = InfluxDBClient( + 'host', 8086, 'username', 'password', 'database', ssl=True, + path="somepath" + ) + self.assertEqual('https://host:8086/somepath', cli._baseurl) + + cli = InfluxDBClient( + 'host', 8086, 'username', 'password', 'database', ssl=True, + path=None + ) + self.assertEqual('https://host:8086', cli._baseurl) + + cli = InfluxDBClient( + 'host', 8086, 'username', 'password', 'database', ssl=True, + path="/somepath" + ) + self.assertEqual('https://host:8086/somepath', cli._baseurl) + def test_dsn(self): """Set up the test datasource name for TestInfluxDBClient object.""" cli = InfluxDBClient.from_dsn('influxdb://192.168.0.1:1886') pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy