I have a quite concerning problem with this API. I am using this API to perform six different queries one after the other. However the between the queries I save the resulting pandas dataframes into csv files.
After this phase, I proceed to read the csv files and perform some operations (I substitute the NaN values with 0 in the column called '_value'). The problem is that, in some executions of the code, the csv files seems to miss some columns or are not filled. It returns the following error:
Traceback (most recent call last):
File "Path\code.py", line 136, in <module>
fd['_value'] = fd["_value"].fillna(0)
File "Path\Anaconda3\envs\tf\lib\site-packages\pandas\core\frame.py", line 3505, in __getitem__
indexer = self.columns.get_loc(key)
File "Path\Anaconda3\envs\tf\lib\site-packages\pandas\core\indexes\base.py", line 3631, in get_loc
raise KeyError(key) from err
KeyError: '_value'
Exception ignored in: <function InfluxDBClient.__del__ at 0x000002723CB52170>
Traceback (most recent call last):
File "Path\Anaconda3\envs\tf\lib\site-packages\influxdb_client\client\influxdb_client.py", line 284, in __del__
File "Path\Anaconda3\envs\tf\lib\site-packages\influxdb_client\_sync\api_client.py", line 84, in __del__
File "Path\Anaconda3\envs\tf\lib\site-packages\influxdb_client\_sync\api_client.py", line 661, in _signout
TypeError: 'NoneType' object is not callable
Exception ignored in: <function ApiClient.__del__ at 0x000002723CB53BE0>
Traceback (most recent call last):
File "Path\Anaconda3\envs\tf\lib\site-packages\influxdb_client\_sync\api_client.py", line 84, in __del__
File "Path\Anaconda3\envs\tf\lib\site-packages\influxdb_client\_sync\api_client.py", line 661, in _signout
TypeError: 'NoneType' object is not callable
I don't know how to solve this problem and why sometimes occurs and why sometimes not. Below you can see the code for which I do the queries.
from influxdb_client import InfluxDBClient
client = InfluxDBClient(
url=url,
token=token,
org=org
)
query_api = client.query_api()
df = query_api.query_data_frame(query_1)
df.to_csv('path_to_file/name1.csv')
df = query_api.query_data_frame(query_2)
df.to_csv('path_to_file/name2.csv')
df = query_api.query_data_frame(query_3)
df.to_csv('path_to_file/name3.csv')
df = query_api.query_data_frame(query_4)
df.to_csv('path_to_file/name4.csv')
df = query_api.query_data_frame(query_5)
df.to_csv('path_to_file/name5.csv')
df = query_api.query_data_frame(query_6)
df.to_csv('path_to_file/name6.csv')
client.close()
To write this code I followed the examples at GitHub Influxdb-Client Python: Queries with pandas dataframe
Should I do somenthing like: open the client -> query -> save file -> close the client -> repeat?
EDIT: open the client -> query -> save file -> close the client -> repeat, did not solve anything.