admin管理员组文章数量:1316540
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
1 Answer
Reset to default 0You 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'],
]);
本文标签: php403 Forbidden Access blocked bei guzzlehttp GET nominatimopenstreetmaporgStack Overflow
版权声明:本文标题:php - 403 Forbidden: Access blocked bei guzzlehttp GET nominatim.openstreetmap.org - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742006798a2412120.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论