我正在使用geopy来对某些地址进行地理编码,并且想要捕获超时错误并将其打印出来,以便我可以对输入进行一些质量控制。我将地理编码请求放入try/catch中,但它不起作用。关于我需要做什么的任何想法?Geopy:捕获超时错误
这里是我的代码:
try:
location = geolocator.geocode(my_address)
except ValueError as error_message:
print("Error: geocode failed on input %s with message %s"%(a, error_message))
我得到以下异常:
File "/usr/local/lib/python2.7/site-packages/geopy/geocoders/base.py", line 158, in _call_geocoder
raise GeocoderTimedOut('Service timed out')
geopy.exc.GeocoderTimedOut: Service timed out
预先感谢您!
您正在捕获错误异常;你需要捕捉的异常是'GeocoderTimedOut'。 –