3

I have PHP app which sends url request for geocoding as:

http://nominatim.openstreetmap.org/reverse?format=xml&lat=33&lon=34&addressdetails=1

when I copy to browser returns XML respond. When same url sending from PHP file have response as:

<html><head><title>Bandwidth limit exceeded</title></head><body><h1>Bandwidth limit exceeded</h1><p>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.</p><p>For more information, consult the <a href="http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy">usage policy</a> for the OSM Nominatim server.</body></head>

that request is sending every 5 minutes which is not violating 1 sec min. request restriction. How can avoid to have that error message?

// Send to nomintaim server reverse geocoding request 
    $url = "http://nominatim.openstreetmap.org/reverse?format=xml&lat=" . $loc['lat'] . "&lon=" . $loc['lng']. "&addressdetails=1";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    $result = curl_exec($ch);
    curl_close($ch);
scai
  • 20,297
  • 4
  • 56
  • 72
Vitali
  • 95
  • 1
  • 2
  • 6
  • "that you send a valid UserAgent or Referer" , please add the php code you use – cske Sep 12 '16 at 06:20
  • I added the code to main question – Vitali Sep 12 '16 at 06:38
  • AFAIK curl won't set up UserAgent or Referer header for you that shoud be included by you, "you have not provided sufficient identification of your application" have you got any code for identify yourself for api? – cske Sep 12 '16 at 06:43
  • You have already exceeded the bandwidth limit. Wait until you get unblocked, then try again. Read the [usage policy](https://wiki.openstreetmap.org/wiki/Nominatim_usage_policy), alternatively [install your own Nominatim instance](https://wiki.openstreetmap.org/wiki/Nominatim/Installation) or use a [third-party Nominatim provider](https://wiki.openstreetmap.org/wiki/Nominatim_usage_policy#Alternatives_.2F_Third-party_providers). – scai Sep 12 '16 at 06:44
  • no any identify codes, first time using nominatim, i am new in php – Vitali Sep 12 '16 at 06:45
  • i did not exceeded the bandwidth limit its happened after first try – Vitali Sep 12 '16 at 06:48
  • 1
    Seems like you have to use `CURLOPT_USERAGENT` for setting the user-agent with PHP cURL. – scai Sep 12 '16 at 06:50
  • scai- works excellent now as your answer – Vitali Sep 12 '16 at 07:04

1 Answers1

3

You should use CURLOPT_USERAGENT & CURLOPT_REFERER like this :

$userAgent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2';
curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent );
curl_setopt($ch, CURLOPT_REFERER, 'http://www.example.com/1');