Hello! I have such a question, urllib.request.urlopen() does not accept Cyrillic characters in the http request,
I fulfill:

 urllib.request.urlopen('http://exemple.com/sent?"русский_текст"') 

I get:

 self._output(request.encode('ascii')) UnicodeEncodeError: 'ascii' codec can't encode characters in position 11-17: ordinal not in range(128) 

After reading the documentation on urllib.request, I realized that urllib.request.urlopen () is trying to translate my request to latin 1 (iso8859-1) and this is exactly what he swears about, how to handle the request with Cyrillic characters correctly?

    1 answer 1

     urllib.request.urlopen('http://example.com/send?{0}'.format(quote_plus('"русский_текст"'))) 

    or even like this:

     urlopen(urlunparse(('http', 'example.com', '/send', None, quote_plus('"русский текст"'), None), )) 

    But in general, requests for many things are a little easier to do.

    • Thanks, it really helped. - warlok 4:16 pm