Skip to content Skip to sidebar Skip to footer

Unicode String In Urllib.request

The short version: I have a variable s = 'bär'. I need to convert s to ASCII so that s = 'b%C3%A4r'. Long version: I'm using urllib.request.urlopen() to read an mp3 pronunciation

Solution 1:

Use urllib.parse.quote:

>>> urllib.parse.quote('bär')
'b%C3%A4r'

>>> urllib.parse.urljoin('https://d7mj4aqfscim2.cloudfront.net/tts/de/token/',
...                      urllib.parse.quote('bär'))
'https://d7mj4aqfscim2.cloudfront.net/tts/de/token/b%C3%A4r'

Post a Comment for "Unicode String In Urllib.request"