我正在使用geopy对一些地址进行地理编码,希望能捕获超时错误并将其打印出来,以便我可以对输入进行质量控制。我尝试使用try/catch语句包装geocode请求,但似乎并没有起作用。请问我需要怎么做?
以下是我的代码:
以下是我的代码:
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
。 - Burhan Khalid