I have a socket receives some binary data sent by the server, the server is written in C++. it sends binary data like: 0x10, 0x20, 0x18, 0xAA etc.
In python 2 I used to be able to receive the data and append it to a string, but now in Python 3 what I received is a byte array, how do I convert that into a string?
decode('utf-8') doesn't seem to work, Here is my original code:
reply_string = "" while bytes_read < reply_length:
chunk = s.recv(4096)
reply_string += chunk.decode('utf-8')
s is a socket, the error I got is:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf7 in position 116: invalid start byte
The server is written in C++, it doesn't send unicode, it simply read the content of a binary file and send it back to the client, above is the client code.
0x10 0x20 ...as text?strtype and the Python 3bytestype behave very similarly. If your code worked in Python 2.7, I would expect it to continue working in 3.X, no type conversion required. Can you provide a minimal reproducible example that demonstrates the problem?