0

I would like to convert this : b'\xff\xff\xff\xff\xff\xff\x00\x1b!!\x9c'

to this : '\xff\xff\xff\xff\xff\xff\x00\x1b!!\x9c'

There is an easy way? b'\xff\xff\xff\xff\xff\xff\x00\x1b!!\x9c'.decode() creates an error builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
stef9999
  • 17
  • 3
  • 3
    Does this answer your question? [Convert bytes to a string](https://stackoverflow.com/questions/606191/convert-bytes-to-a-string). This is, by the way, the first result of googling "python byte to string"... – Tomerikoo Jan 22 '20 at 13:40
  • Unfortunatly, this is not answering my question. – stef9999 Jan 22 '20 at 14:02
  • It does answer your question, but the encoding you want is probably `.decode('iso8859')`, not `.decode('utf-8')`. If the data is supposed to be a string then you should check what encoding is used by whereever the data comes from. – kaya3 Jan 22 '20 at 14:13

1 Answers1

1

It's a hack -- but it works:

str data = str(data)
data = data[2:] 
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65