diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be04918..d5127763 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Bug Fixes 1. [#375](https://github.com/influxdata/influxdb-client-python/pull/375): Construct `InfluxDBError` without HTTP response 1. [#378](https://github.com/influxdata/influxdb-client-python/pull/378): Correct serialization DataFrame with nan values [DataFrame] +1. [#384](https://github.com/influxdata/influxdb-client-python/pull/384): Timeout can be specified as a `float` ### CI 1. [#370](https://github.com/influxdata/influxdb-client-python/pull/370): Add Python 3.10 to CI builds diff --git a/influxdb_client/rest.py b/influxdb_client/rest.py index 8fc5e53a..df7b474f 100644 --- a/influxdb_client/rest.py +++ b/influxdb_client/rest.py @@ -161,7 +161,7 @@ def request(self, method, url, query_params=None, headers=None, timeout = None _configured_timeout = _request_timeout or self.configuration.timeout if _configured_timeout: - if isinstance(_configured_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821 + if isinstance(_configured_timeout, (int, float, ) if six.PY3 else (int, long, float, )): # noqa: E501,F821 timeout = urllib3.Timeout(total=_configured_timeout / 1_000) elif (isinstance(_configured_timeout, tuple) and len(_configured_timeout) == 2): diff --git a/tests/test_InfluxDBClient.py b/tests/test_InfluxDBClient.py index 94efcf77..975978a2 100644 --- a/tests/test_InfluxDBClient.py +++ b/tests/test_InfluxDBClient.py @@ -4,10 +4,11 @@ import threading import unittest -from urllib3.exceptions import NewConnectionError +import pytest +from urllib3.exceptions import NewConnectionError, HTTPError from influxdb_client import InfluxDBClient, Point -from influxdb_client.client.write_api import WriteOptions, WriteType +from influxdb_client.client.write_api import WriteOptions, WriteType, SYNCHRONOUS from tests.base_test import BaseTest @@ -166,6 +167,14 @@ def test_write_context_manager(self): self.assertIsNone(api_client._pool) self.assertIsNone(self.client.api_client) + def test_timeout_as_float(self): + self.client = InfluxDBClient(url="http://localhost:8088", token="my-token", org="my-org", timeout=1000.5) + self.assertEqual(1000.5, self.client.api_client.configuration.timeout) + with pytest.raises(HTTPError) as e: + write_api = self.client.write_api(write_options=SYNCHRONOUS) + write_api.write(bucket="my-bucket", org="my-org", record="mem,tag=a value=1") + self.assertIn("Failed to establish a new connection", str(e.value)) + class InfluxDBClientTestIT(BaseTest): httpRequest = []