Reputation: 5473
so i am using a Django tastypie resource and i am trying to find a generic way to decode any string that may be posted to the resource.
i have for example a Name like this
luiçscoico2#@!&&á
and i want my to be able to identify the type of encoding, and appropriately decode it.
I am trying to fetch the string like this:
print bundle.data.get('first_name')
when i do a json dumps my string first name becomes like
"lui\u00e7scoico2#@!&&\u00e1"
and i get an INTERNAL SERVER ERROR... any ideas?
UPDATE: i do get a
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 3: ordinal not in range(128)
if i try to decode('utf-8') before doing the json dumps to send to the server
Upvotes: 1
Views: 2474
Reputation: 29804
Ok I'm gonna try to give a semi-blind answer here. Your string is already in Unicode
, the reason I know this is because of the u'\xe7' which is exactly the ç
character.
This means you don't have to encode
it. If you need your string in utf-8 then just do:
x.decode('utf-8')
and it will porbably work :)
Hope this helps!
Upvotes: 1