Skip to content

Commit 4f1ab87

Browse files
authoredJan 29, 2024
fix: logging http requests without query parameters (#631)
* fix: logging http requests without query parameters * docs: update CHANGELOG.md
1 parent d7181fa commit 4f1ab87

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Bug Fixes
77
1. [#562](https://github.com/influxdata/influxdb-client-python/pull/562): Use `ThreadPoolScheduler` for `WriteApi`'s batch subject instead of `TimeoutScheduler` to prevent creating unnecessary threads repeatedly
8+
1. [#631](https://github.com/influxdata/influxdb-client-python/pull/631): Logging HTTP requests without query parameters
89

910
## 1.39.0 [2023-12-05]
1011

‎influxdb_client/_sync/rest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def request(self, method, url, query_params=None, headers=None,
170170
headers['Content-Type'] = 'application/json'
171171

172172
if self.configuration.debug:
173-
_BaseRESTClient.log_request(method, f"{url}?{urlencode(query_params)}")
173+
_BaseRESTClient.log_request(method, f"{url}{'' if query_params is None else '?' + urlencode(query_params)}")
174174
_BaseRESTClient.log_headers(headers, '>>>')
175175
_BaseRESTClient.log_body(body, '>>>')
176176

‎tests/test_InfluxDBClient.py

+12
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,18 @@ def test_custom_debug_logging_handler(self):
415415
logger = logging.getLogger('influxdb_client.client.http')
416416
self.assertEqual(2, len(logger.handlers))
417417

418+
def test_debug_request_without_query_parameters(self):
419+
httpretty.register_uri(httpretty.GET, uri="http://localhost/ping", status=200, body="")
420+
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
421+
422+
log_stream = StringIO()
423+
logger = logging.getLogger("influxdb_client.client.http")
424+
logger.addHandler(logging.StreamHandler(log_stream))
425+
426+
self.influxdb_client.api_client.call_api('/ping', 'GET')
427+
428+
self.assertIn("'GET http://localhost/ping'", log_stream.getvalue())
429+
418430

419431
class ServerWithSelfSingedSSL(http.server.SimpleHTTPRequestHandler):
420432
def _set_headers(self, response: bytes):

0 commit comments

Comments
 (0)
Please sign in to comment.