Skip to content

Commit 99cc8ca

Browse files
ynezztrehn
authored andcommitted
Fixes for line-protocol feature
Working again with influxdata/influxdb@246ce61 Signed-off-by: Petr Štetiar <ynezz@true.cz>
1 parent 9b753de commit 99cc8ca

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

influxdb/client.py

100755100644
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def switch_user(self, username, password):
198198
self._password = password
199199

200200
def request(self, url, method='GET', params=None, data=None,
201-
expected_response_code=200):
201+
expected_response_code=200, headers=None):
202202
"""Make a HTTP request to the InfluxDB API.
203203
204204
:param url: the path of the HTTP request, e.g. write, query, etc.
@@ -219,6 +219,9 @@ def request(self, url, method='GET', params=None, data=None,
219219
"""
220220
url = "{0}/{1}".format(self._baseurl, url)
221221

222+
if headers is None:
223+
headers = self._headers
224+
222225
if params is None:
223226
params = {}
224227

@@ -235,7 +238,7 @@ def request(self, url, method='GET', params=None, data=None,
235238
auth=(self._username, self._password),
236239
params=params,
237240
data=data,
238-
headers=self._headers,
241+
headers=headers,
239242
verify=self._verify_ssl,
240243
timeout=self._timeout
241244
)
@@ -264,12 +267,17 @@ def write(self, data, params=None, expected_response_code=204):
264267
:returns: True, if the write operation is successful
265268
:rtype: bool
266269
"""
270+
271+
headers = self._headers
272+
headers['Content-type'] = 'application/octet-stream'
273+
267274
self.request(
268-
url="write_points",
275+
url="write",
269276
method='POST',
270277
params=params,
271278
data=make_lines(data).encode('utf-8'),
272-
expected_response_code=expected_response_code
279+
expected_response_code=expected_response_code,
280+
headers=headers
273281
)
274282
return True
275283

tests/influxdb/client_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def test_write(self):
139139
with requests_mock.Mocker() as m:
140140
m.register_uri(
141141
requests_mock.POST,
142-
"http://localhost:8086/write_points",
142+
"http://localhost:8086/write",
143143
status_code=204
144144
)
145145
cli = InfluxDBClient(database='db')
@@ -162,7 +162,7 @@ def test_write_points(self):
162162
with requests_mock.Mocker() as m:
163163
m.register_uri(
164164
requests_mock.POST,
165-
"http://localhost:8086/write_points",
165+
"http://localhost:8086/write",
166166
status_code=204
167167
)
168168

@@ -182,7 +182,7 @@ def test_write_points_toplevel_attributes(self):
182182
with requests_mock.Mocker() as m:
183183
m.register_uri(
184184
requests_mock.POST,
185-
"http://localhost:8086/write_points",
185+
"http://localhost:8086/write",
186186
status_code=204
187187
)
188188

@@ -221,7 +221,7 @@ def test_write_points_batch(self):
221221
"fields": {"value": 12.00}}]}
222222
with requests_mock.Mocker() as m:
223223
m.register_uri(requests_mock.POST,
224-
"http://localhost:8086/write_points",
224+
"http://localhost:8086/write",
225225
status_code=204)
226226
cli = InfluxDBClient(database='db')
227227
cli.write_points(points=dummy_points,
@@ -278,7 +278,7 @@ def test_write_points_with_precision(self):
278278
with requests_mock.Mocker() as m:
279279
m.register_uri(
280280
requests_mock.POST,
281-
"http://localhost:8086/write_points",
281+
"http://localhost:8086/write",
282282
status_code=204
283283
)
284284

0 commit comments

Comments
 (0)
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