I’m using a url to get the Longitudes and Latitudes for a given city. When I passed
“New York” as the string it wont give any results, but when I passed “New%20York” it did. How to pass the New York like words to a query string?
current_location = 'New york' #not working
current_location2 = 'New%20York' # working
location_string = 'http://maps.googleapis.com/maps/api/geocode/json?address=' +current_location+ '&sensor=false'
Use
urllib.quote()orurllib.quote_plus()to replace characters with their%xxequivalents orurllib.urlencode()to construct the query string from a dictionary of variables you intend to go into the URL. Example: