geopy: Nominatim HTTP Error 403: Forbidden for default User-Agent
Nominatim API seems to block the default User-Agent: Python-urllib/3.5
now: HTTP Error 403: Forbidden.
Looking at the code the default User-Agent should be geopy/1.11.0
? I’ve tried to set own user-agent
by: Nominatim(user_agent='MyApp/1.2.3')
but the request has still the user agent User-Agent: Python-urllib/3.5
and it fails with HTTP 403. So, the user-agent param does not work properly.
Edit: duplicate to #185 and probably solved by #184. Leaving this opened, since the Nominatim has started to block these requests just recently. Just to prevent other folks to duplicate the issue like me.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 15 (1 by maintainers)
Commits related to this issue
- Workaround for Nominatim - addresses #83 — committed to meine-stadt-transparent/meine-stadt-transparent by CatoTH 6 years ago
@edwin34 python2
python3
Note: temporary hack to overcome this issue:
And use it:
Yeah, the reason why these hacks have broken is because the
req
argument of thegeolocator.urlopen
might be aRequest
instance rather than a string url.This problem has been fixed in 3395aee and it’s already released in
1.12.0
, so these hacks are not needed anymore. Nominatim now works out of the box again, as well as supplying a customuser_agent
.I’m closing this.
from geopy.geocoders import Nominatim
def nominatim_hack(geocoder: Nominatim): requester = geocoder.urlopen
def requester_hack(req, **kwargs): req = Request(url=req, headers=geocoder.headers) return requester(req, **kwargs)
geocoder.urlopen = requester_hack
locator = Nominatim() locator = nominatim_hack(locator) location = locator.reverse(“52.509669, 13.376294”) print (location.address)
This doesn’t work for me too, please help me to fix this. It shows the following error:- File “jio.py”, line 3 def nominatim_hack(geocoder: Nominatim): SyntaxError: invalid syntax