i' ve a very simply environment:
In [64]: aa = '\xe1'
In [65]: aa
Out[65]: '\xe1'
In [66]: type(aa)
Out[66]: str
In [67]: u'\xe1'
Out[67]: u'\xe1'
In [68]: u'%s' % aa
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc
in <module>()
----> 1 u'%s' % aa
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe1 in position 0:
ordinal not in range(128)
All I'd like to do is to convert this aa string to unicode. How could i do this?
In the db i've unicode strings, and with str i can' t make a resulting django query if it contains special characters. Using .encode('utf-8') or unicode(aa) i got the same UnicodeDecodeError.
I also tried playing with sys.setdefaultencoding, and then it might work, however it kills everything else.
Python version: 2.7.3