I'm trying to read SERIAL_ID data from module and write it to InfluxDB.
>>> db.write_points([{'fields': {'LENGTH_SMF': 10000, 'ENCODING': 1, 'ENHANCED_OPTIONS': 176, 'CONNECTOR': 7, 'TRANSCEIVER_EXT': 0, 'VENDOR_PN': 'LS38-C3S-TC-N-DD', 'LENGTH_SMF_KM': 10000, 'WAVELENGTH': 1310, 'OPTIONS': '\x00\x1a', 'LENGTH_OM4_OR_CU': 0, 'BR_NOMINAL': 1300, 'LENGTH_62_5UM': 0, 'RATE_IDENTIFIER': 0, 'VENDOR_OUI': '\x00\x0f\x99', 'LENGTH_50UM': 0, 'CABLE_SPEC': '\x00\x00', 'EXT_IDENTIFIER': 4, 'VENDOR_SN': 'B909120227 ', 'IDENTIFIER': 3, 'LENGTH_OM3': 0, 'BR_MIN': 1300, 'SFF_8472_COMPLIANCE': 1, 'DIAGNOSTIC_MONITORING_TYPE': 88, 'TRANSCEIVER': '\x00\x00\x00\x02\x12\x00\x01\x01', 'VENDOR_REV': '0000', 'DATE_CODE': '111101 ', 'VENDOR_NAME': 'APAC Opto ', 'BR_MAX': 1300}, 'tags': {'board': 1, 'port': 'port2'}, 'measurement': 'SERIAL_ID'}])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/influxdb/client.py", line 490, in write_points
tags=tags, protocol=protocol)
File "/usr/lib/python2.7/dist-packages/influxdb/client.py", line 551, in _write_points
protocol=protocol
File "/usr/lib/python2.7/dist-packages/influxdb/client.py", line 315, in write
data = make_lines(data, precision).encode('utf-8')
File "/usr/lib/python2.7/dist-packages/influxdb/line_protocol.py", line 156, in make_lines
value = _escape_value(field_value)
File "/usr/lib/python2.7/dist-packages/influxdb/line_protocol.py", line 92, in _escape_value
value = _get_unicode(value)
File "/usr/lib/python2.7/dist-packages/influxdb/line_protocol.py", line 107, in _get_unicode
return data.decode('utf-8')
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
As workaround I have to used such code:
from binascii import hexlify
...
port_data = oom_get_memory(port, data_type)
for key in port_data:
if key in ['TRANSCEIVER', 'VENDOR_OUI', 'CABLE_SPEC', 'OPTIONS']:
port_data[key] = hexlify(port_data[key]) # Convert data in bytearray format to string
to string
...
I'm trying to read SERIAL_ID data from module and write it to InfluxDB.
As workaround I have to used such code: