我正在尝试将联系人添加到 sendgrid 中,该数据偶尔将用户电子邮件存储在 punycode
无论如何,如果我尝试添加 ascii 版本,则有一个错误,因为 sendgrid 不接受它 - 但是它确实接受了Unicode版本。
因此,有没有办法将它们转换为Python。
因此,我认为长话短说,有没有办法将 punycode 解码为unicode?
编辑
正如我尝试的评论所建议的
'example-email@yahóo.com'.encode('punyCode')。decode()
返回 [email  nbsp; procectived]
,这是不当解决方案。
提前致谢。
I'm trying to add contacts to Sendgrid from a db which occasionally is storing the user email in punycode [email protected]
which translates to example-email@yahóo.com
in Unicode.
Anyway if I try and add the ascii version there's an error because sendgrid doesn't accept it - however it does accept the Unicode version.
So is there a way to convert them in python.
So I think long story short is there a way to decode punycode to Unicode?
Edit
As suggested in comments i tried
'example-email@yahóo.com'.encode('punycode').decode()
which returns [email protected]
so this is incorrect outside of python so is not a valid solution.
Thanks in advance.
发布评论
评论(1)
有
xn -
在您编码的电子邮件地址中:因此,应用
IDNA
编码(请参阅 python> python特定的编码):结果:
反之:
您可以使用
库而不是:
idna
There is the
xn--
ACE prefix in your encoded e-mail address:So apply the
idna
encoding (see Python Specific Encodings):Result:
and vice versa:
You could use the
idna
library instead: