influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
706 stars 185 forks source link

Ping throwing exception when DEBUG is True #630

Closed rusnackor closed 7 months ago

rusnackor commented 7 months ago

Specifications

Code sample to reproduce problem


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.

bednar commented 7 months ago

Hi @rusnackor,

thanks for using our client.

I've prepared PR #631. If you would like to use dev version of client then install client via:

pip install git+https://github.com/influxdata/influxdb-client-python.git@logging-requests-without-query-parameters

Best Regards