I'm receiving unicode data from a client, stored in a dictionary called "data". The following code
variable1 = '\u03b5\u0061\u0073\u0064\u0066'
print("TYPE1 = " + str(type(variable1)))
print("VAR1 = " + variable1)
variable2 = data['text']
print("TYPE2 = " + str(type(variable2)))
print("VAR2 = " + variable2)
prints
TYPE1 = <class 'str'>
VAR1 = εasdf
TYPE2 = <class 'str'>
VAR2 = \u03b5\u0061\u0073\u0064\u0066
This suggests that the data from the client is somehow not interpreted properly. Writing the variables to file also gives the exact same result: the file has the literal "\u03b5\u0061\u0073\u0064\u0066". How can I "reinterpret" that unicode string so that I get the same result as the inline variable?
The following did NOT work:
eval(variable2)(Error: "unexpected character after line continuation character")
With print(variable2.encode().decode()), I get VAR2 = ε.
By using .encode('ascii').decode('unicode_escape'), I get UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
In the shell:
>>> "\u03b5\u0061\u0073\u0064\u0066"
'εasdf'
u'\u03b5\u0061\u0073\u0064\u0066'?