ubuntu使用celery提示UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 3: ordinal n...

[2019-02-24 23:47:34,858: ERROR/ForkPoolWorker-1] Task celery_tasks.tasks.send_register_active_email[c3b8c30e-bb5b-4586-8d01-fe1590985093] raised unexpected: UnicodeDecodeError('ascii', '%s,\xe6\xac\xa2\xe8\xbf\x8e\xe6\x82\xa8\xe6\x88\x90\xe4\xb8\xba\xe5\xa4\xa9\xe5\xa4\xa9\xe7\x94\x9f\xe9\xb2\x9c\xe6\xb3\xa8\xe5\x86\x8c\xe4\xbc\x9a\xe5\x91\x98\xe8\xaf\xb7\xe7\x82\xb9\xe5\x87\xbb\xe4\xb8\x8b\xe9\x9d\xa2\xe9\x93\xbe\xe6\x8e\xa5\xe6\xbf\x80\xe6\xb4\xbb\xe6\x82\xa8\xe7\x9a\x84\xe8\xb4\xa6\xe6\x88\xb7
http://127.0.0.1:8000/user/active/%s', 3, 4, 'ordinal not in range(128)') Traceback (most recent call last): File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/app/trace.py", line 382, in trace_task R = retval = fun(*args, **kwargs) File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/app/trace.py", line 641, in __protected_call__ return self.run(*args, **kwargs) File "/home/zhangbin/Desktop/dailyfresh/celery_tasks/tasks.py", line 27, in send_register_active_email username, token, token) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 3: ordinal not in range(128)
image.png

解决办法在报错的tasks.py文件开头加上

import sys
reload(sys)
sys.setdefaultencoding('utf8')
image.png

完美解决问题

image.png

你可能感兴趣的:(ubuntu使用celery提示UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 3: ordinal n...)