from dbsettings.functions import getValue import requests def name_to_coords(name, api_key=None): URL = "https://maps.googleapis.com/maps/api/geocode/json" api_key = api_key or getValue("google.api.key") payload = {"address": name, "key": api_key} response = requests.get(URL, params=payload).json() try: result = response["results"][0] return result["geometry"]["location"]["lat"], result["geometry"]["location"]["lng"] except: raise ValueError(response)