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.
There is the
xn--ACE prefix in your encoded e-mail address:So apply the
idnaencoding (see Python Specific Encodings):Result:
and vice versa:
You could use the
idnalibrary instead: