UnicodeDecodeError при отправке почты с использованием AppEngine

1

Я использую App Engine mail.EmailMessage, где мой параметр subject является объектом Unicode, включая символы, отличные от ASCII (åäö). Я получаю следующую ошибку:

Traceback (most recent call last):
  File  "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py", line 765, in emit
    self.stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 101: ordinal not in range(128)

Я даже пытался сделать кодировку UTF-8 перед отправкой, но я получаю ту же ошибку.

Обновлено с помощью дополнительного кода:

EmailMessage отправляется с использованием очереди задач с использованием следующего обработчика:

# Task queue handlers
class MailSender(TemplatedRequestHandler):
    def post(self):
        req = self.request
        subject=req.get('subject')
        recipient=req.get('recipient')
        body=req.get('body')
        logging.info(type(subject))
        logging.info(subject)
        message = mail.EmailMessage(sender=u"ProffsKnuten support <[email protected]>", \
            subject=subject, to=recipient, body=body).send()
        logging.info(u'Sent e-mail to %s with subject "%s".', recipient, subject)

Здесь вывод журнала:

INFO     2011-02-21 12:34:53,308 dev_appserver.py:3317] "POST /tasks/mail HTTP/1.1" 200 -
INFO     2011-02-21 12:34:53,329 view.py:696] <type 'unicode'>
INFO     2011-02-21 12:34:53,330 view.py:697] ProffsKnuten.se - Nytt jobb: Bluttan blä
INFO     2011-02-21 12:34:53,330 mail_stub.py:88] MailService.Send
INFO     2011-02-21 12:34:53,330 mail_stub.py:89]   From: ProffsKnuten support <[email protected]>
INFO     2011-02-21 12:34:53,330 mail_stub.py:92]   To: [censored]@gmail.com
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py", line 765, in emit
    self.stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 101: ordinal not in range(128)
INFO     2011-02-21 12:34:53,333 mail_stub.py:104]   Body:
INFO     2011-02-21 12:34:53,343 mail_stub.py:105]     Content-type: text/plain
INFO     2011-02-21 12:34:53,343 mail_stub.py:106]     Data length: 371
INFO     2011-02-21 12:34:53,343 mail_stub.py:211] You are not currently sending out real email.  If you have sendmail installed you can use it by using the server with --enable_sendmail
INFO     2011-02-21 12:34:53,344 view.py:700] Sent e-mail to [censored]@gmail.com with subject "ProffsKnuten.se - Nytt jobb: Bluttan blä".

Update2:

Добавлен исходный код для функции испускания:

def emit(self, record):
    """  
    Emit a record.

    If a formatter is specified, it is used to format the record.
    The record is then written to the stream with a trailing newline.  If
    exception information is present, it is formatted using
    traceback.print_exception and appended to the stream.  If the stream
    has an 'encoding' attribute, it is used to encode the message before
    output to the stream.
    """
    try: 
        msg = self.format(record)
        fs = "%s\n"
        if not hasattr(types, "UnicodeType"): #if no unicode support...
            self.stream.write(fs % msg) 
        else:
            try: 
                if getattr(self.stream, 'encoding', None) is not None:
                    self.stream.write(fs % msg.encode(self.stream.encoding))
                else:
                    self.stream.write(fs % msg) 
            except UnicodeError:
                self.stream.write(fs % msg.encode("UTF-8"))
        self.flush()
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        self.handleError(record)
  • 1
    Это не ваша проблема, но вы всегда должны использовать Python 2.5 с Appengine SDK.
  • 0
    Интересно, что ваша проблема в регистрации, а не в почтовой системе AppEngine. Вы контролируете регистратор или он является частью Appengine?
Показать ещё 6 комментариев
Теги:
google-app-engine
unicode

1 ответ

0
Лучший ответ

Я запускал App Engine, используя Python 2.6 вместо 2.5. В 2.5 он работает как ожидалось.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню