After executing the code:

import urllib.request fhand = urllib.request.urlopen('https://maps.googleapis.com/maps/api/geocode/json?address=Запорожье') 

the compiler generates a whole tirade with the error "UnicodeEncodeError: 'ascii' codec

Latin recognizes. Tried to encode and decode and can not be overcome. Python 3.5, which fully must "support" unicode.

  • Add this to the answer - andreymal
  • If possible, publish the solution found in response to your question . I am sure it will help many of your colleagues in the future. - Nicolas Chabanovsky

2 answers 2

You can use urllib.parse.quote () to encode the part of the URL containing UTF-8.

 import urllib.request from urllib.parse import quote url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + quote('Запорожье') fhand = urllib.request.urlopen(url) 

    I decided using urllib.parse.urlencode() :

     #!/usr/bin/env python3 import urllib.parse api_key = 'key...' addr = 'Запорожье' base_url = 'https://maps.googleapis.com/maps/api/geocode/json?' params = urllib.parse.urlencode({'address':addr ,'key': api_key}) url = base_url + params