Message207017
smtplib has limited support for non-ASCII domain names in the From to To mail address. It only works for punycode-encoded domain names, submitted as unicode string (e.g. server.rcpt(u"user@xn--e1afmkfd.ru").
The following two calls fail:
server.rcpt(u"user@пример.ru"):
File smtplib.py, line 332, in send
s = s.encode("ascii")
UnicodeEncodeError: 'ascii' codec can't encode character '\u03c0' in position 19: ordinal not in range(128)
http://hg.python.org/cpython/file/3.3/Lib/smtplib.py#l332
server.rcpt(b"user@xn--e1afmkfd.ru"):
File email/_parseaddr.py, line 236, in gotonext
if self.field[self.pos] in self.LWS + '\n\r':
TypeError: 'in <string>' requires string as left operand, not int
http://hg.python.org/cpython/file/3.3/Lib/email/_parseaddr.py#l236
There are three ways to solve this (from trivial to complex):
* Make it clear in the documentation what type of input is expected.
* Accept punycode-encoded domain names in email addresses, either in string or binary format.
* Accept Unicode-encoded domain names, and do the punycode encoding in the smtplib if required.
See also
References:
https://tools.ietf.org/html/rfc5891: Internationalized Domain Names in Applications (IDNA): Protocol |
|
Date |
User |
Action |
Args |
2013-12-28 01:49:23 | macfreek | set | recipients:
+ macfreek |
2013-12-28 01:49:23 | macfreek | set | messageid: <1388195363.36.0.929515660511.issue20083@psf.upfronthosting.co.za> |
2013-12-28 01:49:23 | macfreek | link | issue20083 messages |
2013-12-28 01:49:21 | macfreek | create | |
|