I am receiving data via GET request parameters. Some of theese parameters are strings, and I'm having a tough time being able to display them correctly due to encoding issues I guess.
This is an example of what I receive:
{'id_origen': u'9', 'apellidos': u'\xd1\xe9rez', 'nombre': u'Pimp\xe1m'}
You can see that the value for the key 'apellidos' isn't being received properly. It appears
u'\xd1\xe9rez'
instead of
Núñez.
I tried to solve this issues in a very primitive way, replaceing each appearance of a character like "\xe1" with "á", for example. But it is giving me problems also. This is the code I came up with:
tabla = {'\xE1':'á', '\xE9':'é', '\xED': 'í', '\xF3':'ó', '\xFA':'ú'}
logger.info ("Valor del argumento antes del bucle de urldecode: %s" % valor)
for k, v in tabla.iteritems():
if k in valor:
valor.replace(k, v)
Of course, it doesn't work as I had expected.
What would be the appropiate treatment for theese type of character encoding that I'm receiving?