damianbraun/nominatim

OSM HTTP Error 403: Forbidden

Opened this issue · 0 comments

pat1 commented

According to:
http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy#Requirements
we need to set HTTP Referer or we get urllib2.HTTPError: HTTP Error 403: Forbidden

req.add_header('Referer',YOUR SITE)
solve the problem but we have to set it in def init(self, base_url=None)

    def request(self, url):
        """                                                                                                                                                           
        Send a http request to the given *url*, try to decode                                                                                                         
        the reply assuming it's JSON in UTF-8, and return the result                                                                                                  

        :returns: Decoded result, or None in case of an error                                                                                                         
        :rtype: mixed                                                                                                                                                 
        """
        self.logger.debug('url:\n' + url)
        try:
            req = Request(url)
            req.add_header('Referer', 'http://rmap.cc')
            response = urlopen(req)
            return json.loads(response.read().decode('utf-8'))
        except URLError:
        self.logger.info('Server connection problem')
        except Exception:
            self.logger.info('Server format problem')