使用geopy获取地理位置时发现经常会报错:service timed out,
具体是握手时出现timed out:URLError: <urlopen error _ssl.c:761: The handshake operation timed out> During handling of the above exception, another exception occurred:
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)
print([location.latitude, location.longitude])
print(location.raw)
不知道什么原因,有时候能成功获取,有时候报错,据观察,频繁获取的时候容易报错,不知道是不是不允许频繁获取,因此只能加延时。
from geopy.geocoders import Nominatim
import time
geolocator = Nominatim(user_agent="specify_your_app_name_here")
address=["武汉市武汉大学","175 5th Avenue NYC"]
for ad in address:
location = geolocator.geocode(ad,timeout=10)
print(location.address)
print(location.latitude, location.longitude)
print(location.raw)
time.sleep(5)
但是加了延时发现还是有时成功有时报错,又加了timeout,结果还是有可能报错。
有哪位大侠知道怎么回事吗,还请指教哈~