damianbraun / nominatim

OSM Nominatim API module
Apache License 2.0
27 stars 10 forks source link

OSM HTTP Error 403: Forbidden #5

Open pat1 opened 8 years ago

pat1 commented 8 years ago

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')