nl: call the method domain_part.encode with an argument string 'idna', on the return value call the decode method with string 'ascii' as argument, substitute the result for domain_part.
code: domain_part = domain_part . encode ( 'idna' ) . decode ( 'ascii' )