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