最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - 403 Forbidden: Access blocked bei guzzlehttp GET nominatim.openstreetmap.org - Stack Overflow

programmeradmin1浏览0评论

I get the following error:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET ;street=Kantatenweg+25&city=Leipzig&postalcode=04229&country=Germany&addressdetails=1 resulted in a 403 Forbidden response:

 <html> <head> <title>Access blocked</title> </head> <body> <h1>Access blocked</h1> <p>You have been blocked because you have violated the usage policy of OSM's Nominatim geocoding service. Please be aware that OSM's resources are limited and shared between many users. The usage policy is there to ensure that the service remains usable for everybody.

...

This is what my source text looks like. I am grateful for any advice.

<?php

use maxh\Nominatim\Nominatim;
use GuzzleHttp\Client;
   
    $adresse        = [
        'strasse'   =>  $strasseXml,
        'ort'       =>  $datensatz['Ort'],
        'plz'       =>  $datensatz['PLZ']        
    ];

    $url = "/";

    $defaultHeader = [
        'verify' => false,
        'headers', array('User-Agent' => 'api_client')
    ];

    $client = new Client([
        'base_uri'           => $url,
        'timeout'            => 30,
        'connection_timeout' => 5,
    ]);

    $nominatim      = new Nominatim($url);

        $search         = $nominatim->newSearch()
                        ->street($adresse['strasse'])
                        ->city($adresse['ort'])
                        ->postalCode($adresse['plz'])
                        ->country('Germany')
                        ->addressDetails();
        try {
            $ergebnis = $nominatim->find($search);
        } catch (\GuzzleHttp\Exception\ClientException $e) {
        echo "Fehlermeldung: " . $e->getMessage() . "\n";
        echo "HTTP-Code: " . $e->getResponse()->getStatusCode() . "\n";
        echo "Antwort: " . $e->getResponse()->getBody()->getContents() . "\n";
        }

I am submitting the address Kantatenweg+25, Leipzig, 04229, Germany + addressdetails=1 and would like to receive the coordinates.

After displaying the complete error code, I know what to do.

Many thanks to @c3roe!

I get the following error:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://nominatim.openstreetmap./search?format=json&street=Kantatenweg+25&city=Leipzig&postalcode=04229&country=Germany&addressdetails=1 resulted in a 403 Forbidden response:

 <html> <head> <title>Access blocked</title> </head> <body> <h1>Access blocked</h1> <p>You have been blocked because you have violated the usage policy of OSM's Nominatim geocoding service. Please be aware that OSM's resources are limited and shared between many users. The usage policy is there to ensure that the service remains usable for everybody.

...

This is what my source text looks like. I am grateful for any advice.

<?php

use maxh\Nominatim\Nominatim;
use GuzzleHttp\Client;
   
    $adresse        = [
        'strasse'   =>  $strasseXml,
        'ort'       =>  $datensatz['Ort'],
        'plz'       =>  $datensatz['PLZ']        
    ];

    $url = "http://nominatim.openstreetmap./";

    $defaultHeader = [
        'verify' => false,
        'headers', array('User-Agent' => 'api_client')
    ];

    $client = new Client([
        'base_uri'           => $url,
        'timeout'            => 30,
        'connection_timeout' => 5,
    ]);

    $nominatim      = new Nominatim($url);

        $search         = $nominatim->newSearch()
                        ->street($adresse['strasse'])
                        ->city($adresse['ort'])
                        ->postalCode($adresse['plz'])
                        ->country('Germany')
                        ->addressDetails();
        try {
            $ergebnis = $nominatim->find($search);
        } catch (\GuzzleHttp\Exception\ClientException $e) {
        echo "Fehlermeldung: " . $e->getMessage() . "\n";
        echo "HTTP-Code: " . $e->getResponse()->getStatusCode() . "\n";
        echo "Antwort: " . $e->getResponse()->getBody()->getContents() . "\n";
        }

I am submitting the address Kantatenweg+25, Leipzig, 04229, Germany + addressdetails=1 and would like to receive the coordinates.

After displaying the complete error code, I know what to do.

Many thanks to @c3roe!

Share Improve this question edited Jan 29 at 21:12 Thomas Kujawa asked Jan 29 at 9:26 Thomas KujawaThomas Kujawa 294 bronze badges 4
  • 2 Is there a way to get the non-truncated version of the error message? Your best hint about the reason can be found there. – teapot418 Commented Jan 29 at 9:29
  • @teapot418 Unfortunately, I have no idea how to do this. – Thomas Kujawa Commented Jan 29 at 10:01
  • It's https, so capturing the encrypted traffic won't help you. You can consult the API Usage policy and try to guess the reason, edit the library to give you (or log) the full message or try to reproduce the same request by hand using something like wget or curl. – teapot418 Commented Jan 29 at 10:05
  • 1 See here how to get the full response body when you get such a guzzle exception: stackoverflow/q/19748105/1427878 – C3roe Commented Jan 29 at 10:30
Add a comment  | 

1 Answer 1

Reset to default 0

You need to set a User Agent on the Client. I tested this snippet so you should be fine with just pasting it for testing purposes but i recommend to outsource the actual string to a config file.

$client = new Client([
    'base_uri'           => $url,
    'timeout'            => 30,
    'connection_timeout' => 5,
    'headers' => ['User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36'],
    ]);
发布评论

评论列表(0)

  1. 暂无评论