call the decode function with argument string 'ascii' on the return value of the method domain.encode with argument string 'idna' substitute the result for domain.
domain = domain . encode ( 'idna' ) . decode ( 'ascii' )