Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 94f4add

Browse files
Added headers parameter to InfluxDBClient
1 parent d5d1249 commit 94f4add

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

influxdb/client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class InfluxDBClient(object):
6161
:type proxies: dict
6262
:param path: path of InfluxDB on the server to connect, defaults to ''
6363
:type path: str
64+
:param headers: headers to add to Requests, will add 'Content-Type'
65+
and 'Accept' unless these are already present, defaults to {}
66+
:type headers: dict
6467
"""
6568

6669
def __init__(self,
@@ -78,6 +81,7 @@ def __init__(self,
7881
proxies=None,
7982
pool_size=10,
8083
path='',
84+
headers=None,
8185
):
8286
"""Construct a new InfluxDBClient object."""
8387
self.__host = host
@@ -126,10 +130,11 @@ def __init__(self,
126130
self._port,
127131
self._path)
128132

129-
self._headers = {
130-
'Content-Type': 'application/json',
131-
'Accept': 'text/plain'
132-
}
133+
if headers is None:
134+
headers = {}
135+
headers.setdefault('Content-Type', 'application/json')
136+
headers.setdefault('Accept', 'text/plain')
137+
self._headers = headers
133138

134139
@property
135140
def _baseurl(self):
@@ -303,7 +308,7 @@ def write(self, data, params=None, expected_response_code=204,
303308
:returns: True, if the write operation is successful
304309
:rtype: bool
305310
"""
306-
headers = self._headers
311+
headers = self._headers.copy()
307312
headers['Content-Type'] = 'application/octet-stream'
308313

309314
if params:

0 commit comments

Comments
 (0)