Skip to content

Commit 2f129c2

Browse files
committed
add option to use Requests http(s) proxy
The influxdb-python client does not have support for a web proxy although the Requests library provides the possibility to use a web proxy for both http and https requests. This PR (optionally) adds the feature to use a http(s) proxy by adding an additional parameter to InfluxDBClient initialization called´"proxies". This parameter expects that a dict is provided. If this is not set it will default to { }. The syntax for the dict is the same as specified in Requests docs: http://docs.python-requests.org/en/latest/user/advanced/#proxies proxies = { "http": "http://10.10.1.10:3128", "https": "http://10.10.1.10:1080", }
1 parent 9ccd8dd commit 2f129c2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

influxdb/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class InfluxDBClient(object):
5555
:type use_udp: int
5656
:param udp_port: UDP port to connect to InfluxDB, defaults to 4444
5757
:type udp_port: int
58+
:param proxies: HTTP(S) proxy to use for Requests, defaults to {}
59+
:type proxies: dict
5860
"""
5961

6062
def __init__(self,
@@ -68,6 +70,7 @@ def __init__(self,
6870
timeout=None,
6971
use_udp=False,
7072
udp_port=4444,
73+
proxies=None,
7174
):
7275
"""Construct a new InfluxDBClient object."""
7376
self._host = host
@@ -90,6 +93,11 @@ def __init__(self,
9093
if ssl is True:
9194
self._scheme = "https"
9295

96+
if proxies is None:
97+
self._proxies = {}
98+
else:
99+
self._proxies = proxies
100+
93101
self._baseurl = "{0}://{1}:{2}".format(
94102
self._scheme,
95103
self._host,
@@ -229,6 +237,7 @@ def request(self, url, method='GET', params=None, data=None,
229237
params=params,
230238
data=data,
231239
headers=headers,
240+
proxies=self._proxies,
232241
verify=self._verify_ssl,
233242
timeout=self._timeout
234243
)

0 commit comments

Comments
 (0)