You're looking for urllib.quote
method:
urllib.quote(u'sanità'.encode('latin1'))
'sanit%E0'
Notice that the output of urllib.quote
will be encoding dependent. For example with a cp437
encoded string the output would be sanit%85
. But well, urllib.quote
will do that kind of scaping.