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.
punycode
encoding (see reference at Python Specific Encodings)?'example-email@yahóo.com'.encode('punycode').decode()
returns[email protected]
and vice versa:'[email protected]'.encode().decode('punycode')
->example-email@yahóo.com
. – Flatulentxn--yah-sqa.com
isn't a valid Punycode/IDN string. You could verify at Punycode converter:yahóo.com
translates to Punycode asxn--yaho-sqa.com
. – Flatulentemail@yahóo.com'.encode('punycode').decode()
returns[email protected]
when really it'sxn--yaho-sqa.com
i'm looking for Also will edit the original question – Coo