binascii

Correct interpretation of hex byte, convert it to float

為{幸葍}努か 提交于 2020-02-06 08:48:24
问题 I am currently trying to connect to an electric meter via RS485. It works quite well so far, except that I have problems reading what the meter is writing back on the RS485 line. I know that the data from the electric meter is correct since I can read it with Docklight and the internal programm of the manufacturer. So my only problem is the conversion of hex bytes that I am getting back. I am receiving >>> b'\x01\x03\x04Ce/\xec\xe2' This should be 8 or 9 hex bytes. I expect to receive

json.loads and Redis in python 3.5

落花浮王杯 提交于 2019-12-06 11:03:31
问题 I created a JSON object with json.dumps() and RPUSH(ed) it in a redis list. When getting back the JSON with LRANGE ( redis.lrange() ) I receive a binary string b'{"si":"00:ff" ... So json.loads() raises an error: *** TypeError: the JSON object must be str, not 'bytes' How should I revert to ascii ? 回答1: In general you want to remember the acronym BADTIE: Bytes Are Decoded Text Is Encoded If you have bytes, you run my_bytes.decode() to get text. If you have text, you run my_text.encode() to

json.loads and Redis in python 3.5

有些话、适合烂在心里 提交于 2019-12-04 17:16:32
I created a JSON object with json.dumps() and RPUSH(ed) it in a redis list. When getting back the JSON with LRANGE ( redis.lrange() ) I receive a binary string b'{"si":"00:ff" ... So json.loads() raises an error: *** TypeError: the JSON object must be str, not 'bytes' How should I revert to ascii ? In general you want to remember the acronym BADTIE: Bytes Are Decoded Text Is Encoded If you have bytes, you run my_bytes.decode() to get text. If you have text, you run my_text.encode() to get bytes. You can also specify the encoding if you know it, but it has a sensible default. 来源: https:/