Here is my code (I am using python 2.7 )
result = " '{0}' is unicode or something: ".format(mongdb['field'])
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 27: ordinal not in range(128)
It looks like a string I read from mongodb contains unicode. And it throws this error. How to fix it to concatenate this unicde with custom string 'is unicode or something:' ?
Thanks in advance
UPDATE
result = u" '{0}' is unicode or something: ".format(mongdb['field'])
works for me
Use a unicode format string (recommended):
result = u" '{0}' is unicode or something: ".format(mongdb['field'])
Or encode the field:
result = " '{0}' is unicode or something: ".format(mongdb['field'].encode('utf-8'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With