Handling Internationalized Domain Names (IDN) in Python

posted February 8th 2010 at 1945 EST in Programming, Python, Web

Internationalized Domain Names or IDN are domain names that contain non ascii characters. It's important to know how to handle these in an application because domain names themselves can actually only contain ascii. Punycode is the way the unicode characters gets encoded into ascii characters in a domain name.

Thankfully python has an encoding language IDNA built in that makes this easy.


>>> a="xn--keh.ws"
>>> a.decode("idna")
u"\u2295.ws"
>>> print a.decode("'idna")
⊕.ws
>>> u"⊕.ws".encode("idna")
"xn--keh.ws"
 

One Response

  1. [...] This post was mentioned on Twitter by Whois UK and Domains J, Python UK. Python UK said: Handling Internationalized Domain Names (IDN) in Python http://bit.ly/agqPE6 [...]

Leave a comment