Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Added headers parameter to InfluxDBClient (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielatom committed Apr 14, 2020
1 parent 5bcfadf commit 7fb5e94
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ class InfluxDBClient(object):
:param session: allow for the new client request to use an existing
requests Session, defaults to None
:type session: requests.Session
:param headers: headers to add to Requests, will add 'Content-Type'
and 'Accept' unless these are already present, defaults to {}
:type headers: dict
:raises ValueError: if cert is provided but ssl is disabled (set to False)
"""

def __init__(self,
Expand All @@ -106,6 +108,7 @@ def __init__(self,
cert=None,
gzip=False,
session=None,
headers=None,
):
"""Construct a new InfluxDBClient object."""
self.__host = host
Expand Down Expand Up @@ -166,10 +169,11 @@ def __init__(self,
self._port,
self._path)

self._headers = {
'Content-Type': 'application/json',
'Accept': 'application/x-msgpack'
}
if headers is None:
headers = {}
headers.setdefault('Content-Type', 'application/json')
headers.setdefault('Accept', 'application/x-msgpack')
self._headers = headers

self._gzip = gzip

Expand Down Expand Up @@ -390,7 +394,7 @@ def write(self, data, params=None, expected_response_code=204,
:returns: True, if the write operation is successful
:rtype: bool
"""
headers = self._headers
headers = self._headers.copy()
headers['Content-Type'] = 'application/octet-stream'

if params:
Expand Down

0 comments on commit 7fb5e94

Please sign in to comment.