I'm getting this error on this line:
logger.debug(u'__call__ with full_name={}, email={}'.format(full_name, email))
Why?
The contents of the name variable is Gonçalves.
The problem is that full_name is a str, not a unicode object.
# -*- coding: UTF-8 -*-
import logging
logging.basicConfig()
logger = logging.getLogger()
logger.warning('testing')
# unicode.format(str) raises an error
name = 'Gonçalves'
print type(name)
print name
try:
message = u'{}'.format(name)
except UnicodeDecodeError as e:
print e
# but logger(unicode) is fine
logging.warn(u'Gonçalves')
# so unicode.format(str.decode()) doesn't raise
name = 'Gonçalves'
print type(name)
print name
message = u'{}'.format(name.decode('utf-8'))
logging.warning(message)
# and neither does unicode.format(unicode)
name = u'Gonçalves'
print type(name)
print name
message = u'{}'.format(name)
logging.warning(message)
This should fix your problem:
full_name, email = [unicode(x, 'utf-8') for x in [full_name, email]]
logger.debug(u'__call__ with full_name={}, email={}'.format(full_name, email))
The problem was that the default encoding of unicode strings is ASCII, which only supports 128 characters. Using UTF-8 will fix this problem.
Disclaimer This could be wrong on specifics, I code in py3 only. Learned all this in about 5 mins.
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