问题描述
我最近下载了 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 上尝试了同样的事情并收到了同样的错误。还尝试四处搜索,但似乎找不到与我的问题有关的任何内容。将不胜感激的帮助。谢谢。
解决方法
请确保使用 Nominatim(user_agent="my-application") 或通过覆盖默认的 user_agent 来指定自定义 user_agent,因为您没有指定相同的内容:
geopy.geocoders.options.default_user_agent = "my-application".
如果未指定自定义 user_agent,则会抛出异常。