I have some string in hex enocoding like this:
data = \xd8\xa7\xdb\x8c \xd9\x84\xda\x86\xdb\x8c<br/> \xd8\xa7\xda\xaf\xd8\xb1\xda\x86\xd9\x87 \xd8\xa7\xd9\x82\xd8\xaf\xd8\xa7\xd9\x85\xd8\xa7\xd8\xaa
It contains some Persian string and some HTML elements.
Using ddcode.com I convert them and get meaningful results(I'm not sure that the string is in hex!), but when I want to decode the strings by python I always get errors.
Using codec:
codecs.decode(data,'hex',errors='ignore')
I get
AssertionError Traceback (most recent call last)
<ipython-input-124-5246163fba41> in <module>()
----> 1 codecs.decode(data,'hex',errors='ignore')
AssertionError: decoding with 'hex' codec failed (AssertionError: )
Using binascii
: binascii.unhexlify(data)
I get:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-126-fbe8c6445b8a> in <module>()
1 import binascii
----> 2 binascii.unhexlify(data)
ValueError: string argument should contain only ASCII characters.
What is your suggestion? is the string in hex? if there is some none hex in the string how can I ignore them during decoding?