Python geopy使用注意事项

使用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,结果还是有可能报错。

有哪位大侠知道怎么回事吗,还请指教哈~

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值