celery icon indicating copy to clipboard operation
celery copied to clipboard

UnicodeEncodeError, if the exception message contains unicode characters

Open kapilratnani opened this issue 11 years ago • 8 comments

The exception raised in one of my tasks had unicode characters as shown below. Due to this i didn't receive an error mail.

It will be great if there is a way to get General celery error mails rather than just Task error mails.

Traceback (most recent call last):
  File "~/python2.7/site-packages/billiard/pool.py", line 1696, in safe_apply_callback
    fun(*args, **kwargs)
  File "~/python2.7/site-packages/celery/worker/job.py", line 383, in on_success
    return self.on_failure(ret_value)
  File "~/python2.7/site-packages/celery/worker/job.py", line 442, in on_failure
    self._log_error(exc_info, send_failed_event=send_failed_event)
  File "~/python2.7/site-packages/celery/worker/job.py", line 513, in _log_error
    task.send_error_email(context, einfo.exception)
  File "~/python2.7/site-packages/celery/app/task.py", line 881, in send_error_email
    self.ErrorMail(self, **kwargs).send(context, exc)
  File "~/python2.7/site-packages/celery/utils/mail.py", line 189, in send
    self.format_body(context),
  File "~/python2.7/site-packages/celery/utils/mail.py", line 184, in format_body
    return self.body.strip().format(**context)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2897-2899: ordinal not in range(128)

kapilratnani avatar Jul 30 '15 10:07 kapilratnani

#1896 This has been reported here before, but no traceback shared.

kapilratnani avatar Jul 30 '15 10:07 kapilratnani

Can #2651 fix this?

kapilratnani avatar Jul 30 '15 10:07 kapilratnani

Same problem here on Celery 3.1.18

Traceback (most recent call last):
  File "python2.7/site-packages/billiard/pool.py", line 1696, in safe_apply_callback
    fun(*args, **kwargs)
  File "python2.7/site-packages/celery/worker/job.py", line 383, in on_success
    return self.on_failure(ret_value)
  File "python2.7/site-packages/celery/worker/job.py", line 442, in on_failure
    self._log_error(exc_info, send_failed_event=send_failed_event)
  File "python2.7/site-packages/celery/worker/job.py", line 513, in _log_error
    task.send_error_email(context, einfo.exception)
  File "python2.7/site-packages/celery/app/task.py", line 881, in send_error_email
    self.ErrorMail(self, **kwargs).send(context, exc)
  File "python2.7/site-packages/celery/utils/mail.py", line 189, in send
    self.format_body(context),
  File "python2.7/site-packages/celery/utils/mail.py", line 184, in format_body
    return self.body.strip().format(**context)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xed' in position 3531: ordinal not in range(128)

benjaoming avatar Sep 21 '15 11:09 benjaoming

*) Same problem without setting EMAIL_CHARSET = 'utf-8'

Give me a little time to investigate if the new setting has an effect... need to trigger the same email.

benjaoming avatar Sep 21 '15 11:09 benjaoming

Using celery 3.1.19 with Django here and still have the same problem - which is kind of annoying. Did this commit made it into 3.1.19 ? Because grepping for EMAIL_CHARSET in my install doesn't show anything...

BrunoDesthuilliers avatar Jan 22 '16 13:01 BrunoDesthuilliers

It was merged into 4.0 dev, not 3.1, but setting the charset to utf-8 by default seems sane to me.

ask avatar Jan 22 '16 20:01 ask

Any chance to get this backported to the 3.1.x branch ?

BrunoDesthuilliers avatar Jun 23 '16 07:06 BrunoDesthuilliers

+1. Is this bug can be fixed in 3.1.x branch?

starplanet avatar Aug 01 '16 09:08 starplanet