Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python try语句使用谷歌地图1.0.2_Python_Google Maps - Fatal编程技术网

Python try语句使用谷歌地图1.0.2

Python try语句使用谷歌地图1.0.2,python,google-maps,Python,Google Maps,我使用的是python模块googlemaps 1.0.2,不能在用户输入未知地址的实例中使用try语句 我收到的错误消息如下所示: GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS 我的方法如下所示(没有API密钥): 我试过: except GoogleMapsError: except 'GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS' 谢谢您可能尚未导入googlemaps.Goog

我使用的是python模块googlemaps 1.0.2,不能在用户输入未知地址的实例中使用try语句

我收到的错误消息如下所示:

GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS
我的方法如下所示(没有API密钥):

我试过:

except GoogleMapsError:
except 'GoogleMapsError: Error 602: G_GEO_UNKNOWN_ADDRESS'

谢谢

您可能尚未导入googlemaps.GoogleMapsError异常

from googlemaps import GoogleMaps, GoogleMapsError

def get_distance(address, destination):
    try:
        gmaps = GoogleMaps(api_key)
        directions = gmaps.directions(address,destination)
        distance = directions['Directions']['Distance']['meters']/1600.0
        return distance
    except GoogleMapsError:
        pass

从googlemaps导入googlemaps,GoogleMapsError
???
from googlemaps import GoogleMaps, GoogleMapsError

def get_distance(address, destination):
    try:
        gmaps = GoogleMaps(api_key)
        directions = gmaps.directions(address,destination)
        distance = directions['Directions']['Distance']['meters']/1600.0
        return distance
    except GoogleMapsError:
        pass