Unexpected behaviour when using python influxdb client on Raspberry

influxdb

#1

Hi, after having successfully run some python code uploading JSON formatted data to an InfluxDB on a VPS instance. The code runs fine on a Ubuntu 16.04 client and also on a Windows client, however the very same code does not provide the same results on a Raspberry Pi 3. Rather than getting a confirmation that the data upload has been successful I am receiving messages like http error 404 and number not JSON seriesable.

I am using Python 3.6 on the Ubuntu and the Windows machines, and 3.4.2 on the Raspberry. Other than that I am not sure why there is a different behaviour. I am beginning to believe that for some reason the python-influxdb package I am using on teh raspberry is outdated, however, I am not sure why that would be. I tried installing both with pip as well as with apt-get, the errors are similar albeit not the same.

Could someone point me in the right direction please? Thanks.
Frank


#2

Can you post your code and the errors your seeing, as well as the versions of influxdb-python you have installed?


#3

Hi Noah, here is the code. Some data and the errors are below. But your main question regarding the influxdb versions seems to be most interesting… On Ubuntu its version 5.0.0, and on Raspbian its 0.1.12. So I guess the next question is how to get the latest version for Raspbian installed? I tried both with pip and apt-get (after running update). Can you let me know?

Update:
just checked and it says that python-influxdb is the latest version (no idea which one - how do I find out?)
however, I also installed python3-influxdb , which is version 0.1.12-1

Thanks for your help.

    def publish_data(self):
        client = InfluxDBClient(INFLUXDB_HOST, '8086', '', '', INFLUXDB_NAME)
        response = client.write_points(self.data, time_precision='s')

data (excerpt):
…‘tags’: {‘Station’: ‘CA48’}, ‘measurement’: ‘Enphase_Watt’}, {‘fields’: {‘value’: 150}, ‘time’: 1528395300, ‘tags’: {‘Station’: ‘CA48’}, ‘measurement’: ‘Enphase_Watt’}, {‘fields’: {‘value’: 125}, ‘time’: 1528395600, ‘tags’: {‘Station’: ‘CA48’}, ‘measurement’: ‘Enphase_Watt’}, {‘fields’: {‘value’: 120}, ‘time’: 1528395900, ‘tags’: {‘Station’: ‘CA48’}, ‘measurement’: ‘Enphase_Watt’}, {‘fields’: {‘value’: 101}, ‘time’: 1528396200, ‘tags’: {‘Station’: ‘CA48’}, ‘measurement’: ‘Enphase_Watt’}]
Exception in thread Read_Enphase:
Traceback (most recent call last):
File “/usr/lib/python3.4/threading.py”, line 920, in _bootstrap_inner
self.run()
File “/home/pi/Documents/Pumpberry/Pumpberry_main_v33 test.py”, line 86, in run
self.publish_data()
File “/home/pi/Documents/Pumpberry/Pumpberry_main_v33 test.py”, line 62, in publish_data
response = client.write_points(self.data, time_precision=‘s’)
File “/usr/local/lib/python3.4/dist-packages/influxdb/client.py”, line 468, in write_points
tags=tags, protocol=protocol)
File “/usr/local/lib/python3.4/dist-packages/influxdb/client.py”, line 532, in _write_points
protocol=protocol
File “/usr/local/lib/python3.4/dist-packages/influxdb/client.py”, line 300, in write
data = make_lines(data, precision).encode(‘utf-8’)
File “/usr/local/lib/python3.4/dist-packages/influxdb/line_protocol.py”, line 159, in make_lines
_convert_timestamp(point[‘time’], precision))))
File “/usr/local/lib/python3.4/dist-packages/influxdb/line_protocol.py”, line 44, in _convert_timestamp
raise ValueError(timestamp)
ValueError: 1528351500


#4

Are you using the system python? What about pyenv?

To see what version of the library you have installed, you can use pip show influxdb. I suggest running pip using the -m argument to the python command to ensure you know which version of python was the target:

pi@raspberrypi:~ $ python3 -m pip show influxdb
Name: influxdb
Version: 5.0.0
Summary: InfluxDB client
Home-page: https://github.com/influxdb/influxdb-python
[...]

You can upgrade to the latest version of the library using pip install --upgrade:

pi@raspberrypi:~ $ python3 -m pip install --upgrade influxdb

#5

Thanks. I now managed to uninstall the old pip and the old influxdb-python, and install the 5.0.0 version for Python3, in spite of the “owned by OS” restrictions. I checked from outside and inside Python3 the version (using print (influxdb.version), and it seems all fine now.

However, the program still produces the same, unexpected results, like printing “True” on the screen in one class instance and printing a Unix time stamp in the other.

Sat Jun 9 10:52:47 2018: 1 0.01 Running process: Read_PVsyst
Sat Jun 9 10:52:47 2018: 1 0.01 Publishing data…
True
Sat Jun 9 10:52:47 2018: 1 0.01 Response:True
Sat Jun 9 10:52:47 2018: 1 0.18 Running process: Read_Enphase
Sat Jun 9 10:52:47 2018: 1 0.18 response:200
Sat Jun 9 10:52:47 2018: 1 0.18 Publishing data…
1528524000


#6

Found the problem. It appears that the _convert_timestamp method of the line_protocol.py is unable to handle non integer unix timestamps on the Raspberry, while it has no problems with non ints on the Windows and Ubuntu machines. Extra-formatting the timestamps with int() has fixed it.


#7

Glad you figured it out! Would you mind opening a GitHub issue so the library maintainers are aware of the issue?