Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSM Proxy missing Headers - HTTP Error 403: Forbidden #360

Open
thorge opened this issue Sep 16, 2019 · 0 comments
Open

OSM Proxy missing Headers - HTTP Error 403: Forbidden #360

thorge opened this issue Sep 16, 2019 · 0 comments

Comments

@thorge
Copy link

thorge commented Sep 16, 2019

Hello!

I tried to proxy OSM maps with Tilestache, uWSGI and NGINX.

"osm_layer": {
      "provider": {
          "name": "proxy",
          "url": "http://a.tile.openstreetmap.org/{Z}/{X}/{Y}.png"
      }
  }

I encountered the following problem:

Sep 16 06:47:27 gis uwsgi[3414]: Traceback (most recent call last):
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/local/lib/python2.7/dist-packages/TileStache/__init__.py", line 393, in __call__
Sep 16 06:47:27 gis uwsgi[3414]:     status_code, headers, content = requestHandler2(self.config, path_info, query_string, script_name)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/local/lib/python2.7/dist-packages/TileStache/__init__.py", line 266, in requestHandler2
Sep 16 06:47:27 gis uwsgi[3414]:     status_code, headers, content = layer.getTileResponse(coord, extension)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/local/lib/python2.7/dist-packages/TileStache/Core.py", line 426, in getTileResponse
Sep 16 06:47:27 gis uwsgi[3414]:     tile = self.render(coord, format)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/local/lib/python2.7/dist-packages/TileStache/Core.py", line 513, in render
Sep 16 06:47:27 gis uwsgi[3414]:     tile = provider.renderTile(width, height, srs, coord)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/local/lib/python2.7/dist-packages/TileStache/Providers.py", line 266, in renderTile
Sep 16 06:47:27 gis uwsgi[3414]:     body = url_opener.open(url, timeout=self.timeout).read()
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/lib/python2.7/urllib2.py", line 435, in open
Sep 16 06:47:27 gis uwsgi[3414]:     response = meth(req, response)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/lib/python2.7/urllib2.py", line 548, in http_response
Sep 16 06:47:27 gis uwsgi[3414]:     'http', request, response, code, msg, hdrs)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/lib/python2.7/urllib2.py", line 473, in error
Sep 16 06:47:27 gis uwsgi[3414]:     return self._call_chain(*args)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
Sep 16 06:47:27 gis uwsgi[3414]:     result = func(*args)
Sep 16 06:47:27 gis uwsgi[3414]:   File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default
Sep 16 06:47:27 gis uwsgi[3414]:     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
Sep 16 06:47:27 gis uwsgi[3414]: urllib2.HTTPError: HTTP Error 403: Forbidden

I could break it down to missing headers, so I tried with different Referers and User-Agents (see https://operations.osmfoundation.org/policies/tiles/ ) but in the end i could break it down to a missing "Accept" header.

When I add the following line to /usr/local/lib/python2.7/dist-packages/TileStache/Providers.py on line 263 in renderTile function, everything works fine:

url_opener.addheaders = [('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3')]

It seems, that the accept header is sufficient for OSM.

Any thoughts on this one? How to fix best? Add a field for accept headers in tilestache.cfg or hardcode to renderTile function? Anything else I'm doing wrong, that this issues comes up? Nobody else with this problem?

@thorge thorge changed the title HTTP Error 403: Forbidden OSM Proxy missing Headers - HTTP Error 403: Forbidden Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant