Skip to content

Commit 554e8a0

Browse files
authored
fix: timeout can be specified as a float (influxdata#384)
1 parent 0ebe302 commit 554e8a0

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Bug Fixes
44
1. [#375](https://github.com/influxdata/influxdb-client-python/pull/375): Construct `InfluxDBError` without HTTP response
55
1. [#378](https://github.com/influxdata/influxdb-client-python/pull/378): Correct serialization DataFrame with nan values [DataFrame]
6+
1. [#384](https://github.com/influxdata/influxdb-client-python/pull/384): Timeout can be specified as a `float`
67

78
### CI
89
1. [#370](https://github.com/influxdata/influxdb-client-python/pull/370): Add Python 3.10 to CI builds

influxdb_client/rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def request(self, method, url, query_params=None, headers=None,
161161
timeout = None
162162
_configured_timeout = _request_timeout or self.configuration.timeout
163163
if _configured_timeout:
164-
if isinstance(_configured_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
164+
if isinstance(_configured_timeout, (int, float, ) if six.PY3 else (int, long, float, )): # noqa: E501,F821
165165
timeout = urllib3.Timeout(total=_configured_timeout / 1_000)
166166
elif (isinstance(_configured_timeout, tuple) and
167167
len(_configured_timeout) == 2):

tests/test_InfluxDBClient.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import threading
55
import unittest
66

7-
from urllib3.exceptions import NewConnectionError
7+
import pytest
8+
from urllib3.exceptions import NewConnectionError, HTTPError
89

910
from influxdb_client import InfluxDBClient, Point
10-
from influxdb_client.client.write_api import WriteOptions, WriteType
11+
from influxdb_client.client.write_api import WriteOptions, WriteType, SYNCHRONOUS
1112
from tests.base_test import BaseTest
1213

1314

@@ -166,6 +167,14 @@ def test_write_context_manager(self):
166167
self.assertIsNone(api_client._pool)
167168
self.assertIsNone(self.client.api_client)
168169

170+
def test_timeout_as_float(self):
171+
self.client = InfluxDBClient(url="http://localhost:8088", token="my-token", org="my-org", timeout=1000.5)
172+
self.assertEqual(1000.5, self.client.api_client.configuration.timeout)
173+
with pytest.raises(HTTPError) as e:
174+
write_api = self.client.write_api(write_options=SYNCHRONOUS)
175+
write_api.write(bucket="my-bucket", org="my-org", record="mem,tag=a value=1")
176+
self.assertIn("Failed to establish a new connection", str(e.value))
177+
169178

170179
class InfluxDBClientTestIT(BaseTest):
171180
httpRequest = []

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