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

Added headers parameter to InfluxDBClient #710

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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