Search code examples
pythonjupyter-notebookjupytergeopynominatim

ConfigurationError While using Nominatim in Jupyter Notebook


I recently downloaded geopy and tested it out on Jupyter's notebook with the code below.

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

After running this I received the following error:

---------------------------------------------------------------------------
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"`.

I tried the same thing on Pycharm and received the same error. Also tried searching around but couldn't seem to find anything pertaining to my problem. Would appreciate the help. Thanks.


Solution

  • kindly make sure to specify a custom user_agent with Nominatim(user_agent="my-application") or by overriding the default user_agent as you have not specified the same :

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

    An exception will be thrown if a custom user_agent is not specified.