Repository: influxdata/influxdb-client-python

Issue:
Ping throwing exception when DEBUG is True
### Specifications

* Client Version:  influxdb-client-python/1.36.0
* InfluxDB Version:  v2.7.1
* Platform:  alpine-linux


### Code sample to reproduce problem

```python

from influxdb_client import InfluxDBClient

client = InfluxDBClient(url='http://localhost:8086', token="MyToken==", org='myorganization', timeout=30000, debug=True)
client.api_client.call_api('/ping', 'GET')

```


### Expected behavior

I am using connection check method from official example: examples/connection_check.py to see if my DB is connected.

This is working fine, when I  have `debug=False`, it will simply pass.

### Actual behavior

However, when I do `debug=True` I will get this exception:

```
python3 examples/debug_test.py 
Traceback (most recent call last):
  File "/usr/lib/python3.10/urllib/parse.py", line 947, in urlencode
    if len(query) and not isinstance(query[0], tuple):
TypeError: object of type 'NoneType' has no len()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/examples/debug_test.py", line 5, in <module>
    client.api_client.call_api('/ping', 'GET')
  File "/usr/lib/python3.10/site-packages/influxdb_client/_sync/api_client.py", line 343, in call_api
    return self.__call_api(resource_path, method,
  File "/usr/lib/python3.10/site-packages/influxdb_client/_sync/api_client.py", line 173, in __call_api
    response_data = self.request(
  File "/usr/lib/python3.10/site-packages/influxdb_client/_sync/api_client.py", line 365, in request
    return self.rest_client.GET(url,
  File "/usr/lib/python3.10/site-packages/influxdb_client/_sync/rest.py", line 268, in GET
    return self.request("GET", url,
  File "/usr/lib/python3.10/site-packages/influxdb_client/_sync/rest.py", line 173, in request
    _BaseRESTClient.log_request(method, f"{url}?{urlencode(query_params)}")
  File "/usr/lib/python3.10/urllib/parse.py", line 955, in urlencode
    raise TypeError("not a valid non-string sequence "
  File "/usr/lib/python3.10/urllib/parse.py", line 947, in urlencode
    if len(query) and not isinstance(query[0], tuple):
TypeError: not a valid non-string sequence or mapping object
```

### Additional info

I was trying different formats of debug variable (string, etc) but none seems to work, boolean is only working option, it seems like there is something in `urllib`.

Discussion:
codecov-commenter: ## [Codecov](https://app.codecov.io/gh/influxdata/influxdb-client-python/pull/631?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`d7181fa`)](https://app.codecov.io/gh/influxdata/influxdb-client-python/commit/d7181fab9612dd0558822fc40e5d9ccf5a15d56b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) 90.36% compared to head [(`f2a6c97`)](https://app.codecov.io/gh/influxdata/influxdb-client-python/pull/631?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) 90.39%.


:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #631      +/-   ##
==========================================
+ Coverage   90.36%   90.39%   +0.02%     
==========================================
  Files          39       39              
  Lines        3497     3497              
==========================================
+ Hits         3160     3161       +1     
+ Misses        337      336       -1     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/influxdata/influxdb-client-python/pull/631?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f2cb4d..6f11f45 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
 
 ### Bug Fixes
 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
+1. [#631](https://github.com/influxdata/influxdb-client-python/pull/631): Logging HTTP requests without query parameters
 
 ## 1.39.0 [2023-12-05]
 
diff --git a/influxdb_client/_sync/rest.py b/influxdb_client/_sync/rest.py
index 2d80de1..eadbf06 100644
--- a/influxdb_client/_sync/rest.py
+++ b/influxdb_client/_sync/rest.py
@@ -170,7 +170,7 @@ class RESTClientObject(object):
             headers['Content-Type'] = 'application/json'
 
         if self.configuration.debug:
-            _BaseRESTClient.log_request(method, f"{url}?{urlencode(query_params)}")
+            _BaseRESTClient.log_request(method, f"{url}{'' if query_params is None else '?' + urlencode(query_params)}")
             _BaseRESTClient.log_headers(headers, '>>>')
             _BaseRESTClient.log_body(body, '>>>')
 


Test patch:
diff --git a/tests/test_InfluxDBClient.py b/tests/test_InfluxDBClient.py
index ca37291..c2f9b0a 100644
--- a/tests/test_InfluxDBClient.py
+++ b/tests/test_InfluxDBClient.py
@@ -415,6 +415,18 @@ class InfluxDBClientTestMock(unittest.TestCase):
         logger = logging.getLogger('influxdb_client.client.http')
         self.assertEqual(2, len(logger.handlers))
 
+    def test_debug_request_without_query_parameters(self):
+        httpretty.register_uri(httpretty.GET, uri="http://localhost/ping", status=200, body="")
+        self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
+
+        log_stream = StringIO()
+        logger = logging.getLogger("influxdb_client.client.http")
+        logger.addHandler(logging.StreamHandler(log_stream))
+
+        self.influxdb_client.api_client.call_api('/ping', 'GET')
+
+        self.assertIn("'GET http://localhost/ping'", log_stream.getvalue())
+
 
 class ServerWithSelfSingedSSL(http.server.SimpleHTTPRequestHandler):
     def _set_headers(self, response: bytes):