1

I have a php page that requests reverse geocoding data from Nominatim OSM server. It was working for over a year. Recently started blocking my requests with the following message:

You have been temporarily blocked because you have been overusing OSM's geocoding service or because you have not provided sufficient identification of your application. This block will be automatically lifted after a while. Please take the time and adapt your scripts to reduce the number of requests and make sure that you send a valid UserAgent or Referer.

I am sure that i am not exceeding the quota (1 request / second), because my code is still in pre-production. i might have 1 request / hour on a busy day.

Below a sample of php testing code. I used to get what i needed on line 6 $xml =..., which is now blank / not xml data (so i scrape the page and get the error message):

$latLast = 52.5487429714954;
$lngLast = -1.81602098644987;
$feedUrl = "http://nominatim.openstreetmap.org/reverse?format=xml&lat=".$latLast."&lon=".$lngLast;
$rawFeed = file_get_contents($feedUrl);
try { // nominatim server blocking this ip, must change solution
    $xml = new SimpleXmlElement($rawFeed);
    print_r($xml);
} catch (Exception $e) {
    echo $e->getMessage()."</br>second attempt:</br>";
    try { 
        $html = file_get_html($url);
        echo "HTML2: [$html]</br>";
    } catch (Exception $e) {
        echo $e->getMessage()."</br>";

    }   
} 

How do i send a "valid UserAgent or Referer"? How do i provide "sufficient identification"?

  • 1
    Usage Policy 15,000 requests per month (update 2nd October 2015) wiki.openstreetmap.org/wiki/Nominatim#Usage_Policy mapquest is also limited to 15k developer.mapquest.com/plans (free plan) – Mapperz Oct 9 '15 at 16:18
  • @Mapperz tks for the heads up, but i night have had less than 100 requests this whole month. BUT, the answer was on the osm wiki you pointed me to. all i have to do is supply a valid email address. wanna answer that and get the brownie points? – tony gil Oct 9 '15 at 16:26
2

by including the email parameter in my request, nominatim osm server acccepted that as a valid user agent.

$url = "http://nominatim.openstreetmap.org/reverse?email=myemail@myserver.com&format=xml&lat=-23.56320001&lon=-46.66140002&zoom=27&addressdetails=1";

Nominatim WIKI parameters

0

I had a similar problem while acquiring coordinates for geocoding. I need to add also my email address to url.

I combined info from Nominatim reverse geocode gets blocked - how do i send a valid UserAgent or Referer? and How to header stream_context_create? to get this:

$url = 'https://nominatim.openstreetmap.org/search/'.rawurlencode($location).
'?format=json&limit=1&email=youremail@gmail.com';
$data = ''; // empty post
$opts = array(
    'http' => array(
        'header' => "Content-type: text/html\r\nContent-Length: ".strlen($data).
        "\r\n",
        'method' => 'POST'
    ),
);
// Create a stream
//$opts = array('http'=>array('header'=>"User-Agent: StevesCleverAddressScript 3.7.6\r\n"));
$context = stream_context_create($opts);

// Open the file - get the json response using the HTTP headers set above
$jsonfile = file_get_contents($url, false, $context);
// decode the json 
if (!json_decode($jsonfile, TRUE)) {
    return false;
} else {
    //if (empty(array_filter($resp))) {return false;}else{
    $resp = json_decode($jsonfile, true);
    //if(is_string($resp)){$resp = 'true';}else{$resp = 'itsnot';}
    // Extract data (e.g. latitude and longitude) from the results    
    $gps['latitude'] = $resp[0]['lat'];
    $gps['longitude'] = $resp[0]['lon'];
    return $gps;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.