Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to use GeoPy Nominatim

Tags:

python

I'm new on programing, and I'm using a programing tutorial which said that to use geopy like this:

import pandas, os, geopy
from geopy.geocoders import Nominatim

GeoLocator = Nominatim()

but after the last line I'm getting this error:

/usr/local/lib/python3.7/site-packages/geopy/geocoders/osm.py:143: UserWarning: Using Nominatim with the default "geopy/1.17.0" user_agent 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". In geopy 2.0 this will become an exception. UserWarning

My question is, how should I change my code to fix this error?

like image 782
J.A Avatar asked Oct 01 '18 23:10

J.A


2 Answers

nom = Nominatim(user_agent="http") you have to mention your useragent(HTTP) its just about IP adress

like image 141
Shivam Suchak Avatar answered Sep 22 '22 12:09

Shivam Suchak


You should specify a user_agent. The Nominatum service runs on donated servers which have limited capacity, so specifying a user-agent field allows Open Street Map to track more easily who is using their service. See here for a more detailed answer.

If you don't they may block your IP address from accessing the service as that would be a violation of their terms of service.

like image 28
Andrew McDowell Avatar answered Sep 18 '22 12:09

Andrew McDowell