Using Nominatim with default or sample `user_agent` "my-application" is strongly discouraged, as it violates Nominatim's ToS https://operations.osmfoundation.org/policies/nominatim/ and may possibly cause 403 and 429 HTTP errors. Please specify a custom `user_agent` with `Nominatim(user_agent="my-application")` or by overriding the default `user_agent`: `geopy.geocoders.options.default_user_agent = "my-application"`.
时间: 2024-03-22 09:42:08 浏览: 262
如果你在使用 Geopy 库中的 Nominatim 地理编码器时,出现了以下警告信息:
```python
Using Nominatim with default or sample `user_agent` "my-application" is strongly discouraged, as it violates Nominatim's ToS https://operations.osmfoundation.org/policies/nominatim/ and may possibly cause 403 and 429 HTTP errors. Please specify a custom `user_agent` with `Nominatim(user_agent="my-application")` or by overriding the default `user_agent`: `geopy.geocoders.options.default_user_agent = "my-application"`.
```
这意味着你正在使用 Geopy 库的默认 `user_agent`,这可能会违反 Nominatim 的服务条款并导致 HTTP 403 或 429 错误。为了避免这种情况的发生,建议你使用自定义的 `user_agent`,例如:
```python
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="my_app")
```
在上述示例中,我们将 `my_app` 作为自定义的 `user_agent`。你也可以根据实际需要设置其他值,只要不是 Geopy 库的默认值 `my-application` 即可。
另外,如果你不想在每次创建 Geopy 地理编码器时都手动指定 `user_agent`,可以使用以下代码将默认的 `user_agent` 更改为自定义的值:
```python
from geopy.geocoders.options import default_user_agent
default_user_agent = "my_app"
```
这样,当你创建 Geopy 地理编码器时,就会自动使用自定义的 `user_agent`。
阅读全文
相关推荐


















