It is about Vision API access deny problem , randomly.
My server is running a curl check regularly with google cloud vision API for some pictures. normally, it works well. but randomly the API access will be denyed. I found the error report from error_log as this :
[26-Aug-2023 12:13:35 UTC] PHP Fatal error: Uncaught Google\ApiCore\ApiException: {
"message": "<!DOCTYPE html>\n<html lang=en>\n <meta charset=utf-8>\n <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n <title>Error 403 (Forbidden)!!1</title>\n <style>\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url() 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url() no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url( in /home/aka/ChenJianCronTabTask/vendor/google/gax/src/ApiException.php on line 267
then, since the information is not complete for some reason, I modified ApiException.php and get detail error as below ( most info are html style and I hightlight out useful info) :
Message:{
"message": "<!DOCTYPE html>\n<html lang=en>\n <meta charset=utf-8>\n <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n <title>Error 403 (Forbidden)!!1</title>\n <style>\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url() 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url() no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url() no-repeat 0% 0%/100% 100%;-moz-border-image:url0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:urlno-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n </style>\n <a href=><span id=logo aria-label=Google></span></a>\n <p><b>403.</b> <ins>That\u2019s an error.</ins>\n <p>Your client does not have permission to get URL <code>/v1/images:annotate</code> from this server. <ins>That\u2019s all we know.</ins>\n",
"code": 7,
"status": "PERMISSION_DENIED",
"details": []
}
it confused me. my google key works and this problem only shows up randomly. is there any access limitaion from server site ? or any other potential cause ?
thanks for any help!
I put my php code here:
--------------
//SET UP GOOGLE API CONNECTOR
$google_credential='./google_key/mykey.json';
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
$imageAnnotator = new ImageAnnotatorClient(['credentials' => json_decode(file_get_contents($google_credential), true)]);
$imagefile = "checkitout.jpg";
$response = $imageAnnotator->objectLocalization($imagefile);
- ---- ---- --- ----
my service account key is taken from a json file and authorization is done through initilization.
normally the codes works. but in case of encouting ACCESS DENY problem, it will STOP at objectLocalization() function.
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |