[Django] #28196: Character Encoding on EmailMessage when sending

20 views
Skip to first unread message

Django

unread,
May 12, 2017, 9:06:39 AM5/12/17
to django-...@googlegroups.com
#28196: Character Encoding on EmailMessage when sending
-------------------------------------+-------------------------------------
Reporter: Helmut | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.11
Uncategorized | Keywords: emailmessage, send,
Severity: Normal | email, unicode
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I'm not 100% sure if this is bug, or whether my understand of unicode is
wrong. Nevertheless Django 1.11 behaves differently than 1.10.7. Using
Django 1.10.7, if I send an Email using EmailMessage, but I encode the
subject and body with UTF-8, it sends successfully. For example:
{{{#!python
email = EmailMessage("asd’asd".encode("utf-8"), "asd’asd".encode("utf-8"),
"bl...@foo.com", ["y...@yadda.com"])
email.send()
}}}
But if I run the same code in Django 1.11, it throws an exception because
of the unicode character that was used:
'ascii' codec can't decode byte 0xe2 in position 92: ordinal not in
range(128)

So, might there be a bug in 1.11, or should I not be using the ".encode"?
(Was using that because of weird user input)

And furthermore, why does pre-1.11 not throw an exception?

I thank you for you attention.

--
Ticket URL: <https://code.djangoproject.com/ticket/28196>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 12, 2017, 9:40:38 AM5/12/17
to django-...@googlegroups.com
#28196: Character Encoding on EmailMessage when sending
-------------------------------------+-------------------------------------
Reporter: Helmut | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.11
Severity: Normal | Resolution:
Keywords: emailmessage, send, | Triage Stage:
email, unicode | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Uncategorized => Core (Mail)


Comment:

To help answer your question, you could
[https://docs.djangoproject.com/en/dev/internals/contributing/triaging-
tickets/#bisecting-a-regression bisect] to find the commit where the
behavior changed.

Generally, you should use our
[wiki:TicketClosingReasons/UseSupportChannels support channels] to ask "is
it a bug?" questions rather than seeking help through the ticket tracker.

--
Ticket URL: <https://code.djangoproject.com/ticket/28196#comment:1>

Django

unread,
May 12, 2017, 11:27:58 AM5/12/17
to django-...@googlegroups.com
#28196: Character Encoding on EmailMessage when sending
-------------------------------------+-------------------------------------
Reporter: Helmut | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.11
Severity: Normal | Resolution:
Keywords: emailmessage, send, | Triage Stage:
email, unicode | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz):

There's absolutely no reason to encode the content passed to
`EmailMessage`, so even if it was not failing before, I would be against
restoring the previous behavior.
Nonetheless the EmailMessage `__init__` docstring talks about accepting
UTF-8 bytestrings, which should be removed IMO.
Unless someone comes with a compelling use case to allow bytestrings for
`EmailMessage` subject and body. Binary content should be left for
attachments.

--
Ticket URL: <https://code.djangoproject.com/ticket/28196#comment:2>

Django

unread,
May 12, 2017, 4:15:05 PM5/12/17
to django-...@googlegroups.com
#28196: Character Encoding on EmailMessage when sending
-------------------------------------+-------------------------------------
Reporter: Helmut | Owner: nobody
Type: Bug | Status: closed

Component: Core (Mail) | Version: 1.11
Severity: Normal | Resolution: invalid

Keywords: emailmessage, send, | Triage Stage:
email, unicode | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Helmut):

* status: new => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/28196#comment:3>

Django

unread,
May 14, 2017, 1:47:40 PM5/14/17
to django-...@googlegroups.com
#28196: Character Encoding on EmailMessage when sending
-------------------------------------+-------------------------------------
Reporter: Helmut | Owner: nobody
Type: Bug | Status: closed
Component: Core (Mail) | Version: 1.11
Severity: Normal | Resolution: invalid
Keywords: emailmessage, send, | Triage Stage:
email, unicode | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"d4d812cb567d1f84ef7a569672fdf3c0b83e6fdd" d4d812c]:
{{{
#!CommitTicketReference repository=""
revision="d4d812cb567d1f84ef7a569672fdf3c0b83e6fdd"
Refs #28196 -- Removed mentions of bytestrings for EmailMessage

With Python 3, there are no more reasons to special-case EmailMessage
arguments which should be plain strings.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28196#comment:4>

Reply all
Reply to author
Forward
0 new messages