Odd-length string

Peter Otten __peter__ at web.de
Sun Oct 6 10:31:11 EDT 2013


markotaht at gmail.com wrote:

> print("Key-" + str(võti) + ": " + str(unhexlify("".join(tulemus))))
> 
> IM getting this error on this line. This is the print line of a decryption
> program. I wanti it to convert the tulemus which is in HEX to ASCII so i
> could read it. I could use online translators for the line, but since i
> have 255 lines of the HEX codes, it would be higly unefficient.
> 
> How to i fix the Oddlenght string?

My crystal ball says: strip off the newline byte:

>>> unhexlify(tulemus)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
binascii.Error: Odd-length string
>>> unhexlify(tulemus.rstrip(b"\n"))
b'whatever'





More information about the Python-list mailing list