我正在使用Python中的geocoder包获取一组地址(约30k)的坐标。我遇到了以下错误:
未知状态码 https://maps.googleapis.com/maps/api/geocode/json:ERROR - HTTPSConnectionPool(主机='maps.googleapis.com',端口=443):在url时超出最大重试次数: /maps/api/geocode/json?address=Rancho+Palos+Verdes%2CCA%2CUS&bounds=&components=®ion=&language= (由ProxyError('无法连接到代理。',timeout('已超时',))引起)
如果我添加
以下是代码片段:
未知状态码 https://maps.googleapis.com/maps/api/geocode/json:ERROR - HTTPSConnectionPool(主机='maps.googleapis.com',端口=443):在url时超出最大重试次数: /maps/api/geocode/json?address=Rancho+Palos+Verdes%2CCA%2CUS&bounds=&components=®ion=&language= (由ProxyError('无法连接到代理。',timeout('已超时',))引起)
如果我添加
time.sleep(x)
函数,错误发生的次数会减少,但执行代码的时间显著增加。是否有更有效的方法运行代码?以下是代码片段:
for add in clean_address:
g=geocoder.google(add)
time.sleep(7)
if(g.ok==True):
lat.append(str(g.lat))
lon.append(str(g.lng))
if(g.ok==False):
lat.append("")
lon.append("")