question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nominatim HTTP Error 403: Forbidden for default User-Agent

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
eulercostacommented, Feb 26, 2018

@edwin34 python2

from geopy.geocoders import Nominatim
import urllib2

def get_geolocator():
    geolocator = Nominatim()

    requester = geolocator.urlopen

    def requester_hack(req, **kwargs):
        req = urllib2.Request(url=req, headers=geolocator.headers)
        return requester(req, **kwargs)

    geolocator.urlopen = requester_hack

    return geolocator

location = get_geolocator().reverse("52.509669, 13.376294")
address = location.address

python3

from geopy.geocoders import Nominatim
from urllib.request import Request

def get_geolocator():
    geolocator = Nominatim()

    requester = geolocator.urlopen

    def requester_hack(req, **kwargs):
        req = Request(url=req, headers=geolocator.headers)
        return requester(req, **kwargs)

    geolocator.urlopen = requester_hack

    return geolocator

location = get_geolocator().reverse("52.509669, 13.376294")
address = location.address
10reactions
xmedekocommented, Feb 25, 2018

Note: temporary hack to overcome this issue:

    def nominatim_hack(geocoder: Nominatim):
        """HACK to geopy bugs #262 and #185"""
        requester = geocoder.urlopen

        def requester_hack(req, **kwargs):
            req = Request(url=req, headers=geocoder.headers)
            return requester(req, **kwargs)

        geocoder.urlopen = requester_hack

And use it:

locator = Nominatim()
locator = nominatim_hack(locator)
location = locator.reverse("52.509669, 13.376294")
Read more comments on GitHub >

github_iconTop Results From Across the Web

geopy.exc.GeocoderInsufficientPrivileges: HTTP Error 403
Im trying to use geopy to get the lat/long but it throws a http 403 forbidden error.
Read more >
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 ......
Read more >
HTTP error 403 (Forbidden) accessing tile - OSM Help
I'm trying to fetch a tile https://b.tile.openstreetmap.org/16/35672/23381.png from a Go script, and the server is returning a 403/Forbidden ...
Read more >
Nominatim Returns A Configuration Error After Assigning A ...
Nominatim API seems to block the default UserAgent: Pythonurllib/3.5 now: HTTP Error 403: Forbidden.Looking at the code the default. Nominatim API seems to ......
Read more >
GeoPy Documentation - Read the Docs
By default geopy geocoders are synchronous (i.e. they use an Adapter ... (e.g. by returning Too Many Requests 429 HTTP error or timing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found