【问题标题】:ConfigurationError While using Nominatim in Jupyter Notebook在 Jupyter Notebook 中使用 Nominatim 时出现配置错误
【发布时间】:2021-01-07 15:37:42
【问题描述】:

我最近下载了 geopy 并在 Jupyter 的笔记本上使用以下代码对其进行了测试。

import geopy
from geopy.geocoders import Nominatim
nom=Nominatim(scheme="http")

运行后我收到以下错误:

---------------------------------------------------------------------------
ConfigurationError                        Traceback (most recent call last)
<ipython-input-50-899501bc88f0> in <module>
----> 1 nom=Nominatim(scheme="http")

c:\users\abhilash gupta\appdata\local\programs\python\python39\lib\site-packages\geopy\geocoders\nominatim.py in __init__(self, timeout, proxies, domain, scheme, user_agent, ssl_context, adapter_factory)
    103         if (self.domain == _DEFAULT_NOMINATIM_DOMAIN
    104                 and self.headers['User-Agent'] in _REJECTED_USER_AGENTS):
--> 105             raise ConfigurationError(
    106                 'Using Nominatim with default or sample `user_agent` "%s" is '
    107                 'strongly discouraged, as it violates Nominatim\'s ToS '

ConfigurationError: Using Nominatim with default or sample `user_agent` "geopy/2.1.0" 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"`.

我在 Pycharm 上尝试了同样的事情并收到了同样的错误。还尝试四处搜索,但似乎找不到与我的问题有关的任何内容。将不胜感激。谢谢。

【问题讨论】:

标签: python jupyter-notebook jupyter geopy nominatim


【解决方案1】:

请确保使用 Nominatim(user_agent="my-application") 指定自定义 user_agent 或覆盖默认的 user_agent,因为您没有指定相同的:

geopy.geocoders.options.default_user_agent = "my-application".

如果未指定自定义 user_agent,将引发异常。

【讨论】:

  • 谢谢我明白了,但我们也可以使用?nom=Nominatim(user_agent="http")
猜你喜欢
  • 1970-01-01
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 2020-02-04
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多