小编Che*_*yal的帖子

Python Geopy Nominatim 请求过多

以下脚本与包含 2 行的文件完美配合,但当我尝试 2500 行文件时,出现 429 个异常。所以,我将查询时间增加到了5秒。我还填写了用户代理。尝试失败后,我连接到 VPN 以更改“新鲜”,但再次收到 429 错误。我在这里缺少什么吗?Nominatim 策略指定每秒连接数不得超过 1 个,我每 5 秒执行一个连接...任何帮助都会有帮助!

from geopy.geocoders import Nominatim
import pandas
from functools import partial

from geopy.extra.rate_limiter import RateLimiter

nom = Nominatim(user_agent="xxx@gmail.com")
geocode = RateLimiter(nom.geocode, min_delay_seconds=5)


df=pandas.read_csv('Book1.csv', engine='python')
df["ALL"] = df['Address'].apply(partial(nom.geocode, timeout=1000, language='en'))
df["Latitude"] = df["ALL"].apply(lambda x: x.latitude if x != None else None)
df["Longitude"] = df["ALL"].apply(lambda x: x.longitude if x != None else None)

writer = pandas.ExcelWriter('Book1.xlsx')
df.to_excel(writer, 'new_sheet')
writer.save()
Run Code Online (Sandbox Code Playgroud)

错误信息:

Traceback (most recent call last):
  File "C:\Users\u6022697\AppData\Local\Programs\Python\Python37\lib\site-packages\geopy\geocoders\base.py", …
Run Code Online (Sandbox Code Playgroud)

python geopy python-3.x nominatim http-status-code-429

3
推荐指数
1
解决办法
1万
查看次数