Mercurial > hg > ywww
changeset 37:633402a4995d
try to fix a common lookup error
author | Charlie Root |
---|---|
date | Fri, 04 Jan 2019 14:05:23 -0500 |
parents | e570b199108b |
children | c24ae74bf6d5 |
files | xml/doAmazonRequest.inc |
diffstat | 1 files changed, 20 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/xml/doAmazonRequest.inc Fri Jan 04 12:59:40 2019 -0500 +++ b/xml/doAmazonRequest.inc Fri Jan 04 14:05:23 2019 -0500 @@ -15,13 +15,13 @@ // "nai1: $requestIP $file_data\n",FILE_APPEND); $gotit=0; $url=aws_signed_request($ext,$parameters,$public_key,$private_key); - $crl = curl_init(); - $timeout = 5; - curl_setopt ($crl, CURLOPT_URL,$url); - curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); - curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); for ($i=1; $i<=$try; $i++) { + $crl = curl_init(); + $timeout = 5; + curl_setopt ($crl, CURLOPT_URL,$url); + curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); + curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $semaphore = new SyncSemaphore("Amazon"); $gotit = $semaphore->lock(1000); if (!$gotit) { @@ -58,8 +58,20 @@ } file_put_contents('/var/ywww/debug/phpDebug',"Losing $i: ".$mm[0].", $resName, $code, $requestIP, $requestURI\n",FILE_APPEND); if ($code!='RequestThrottled') { - file_put_contents('/var/ywww/debug/phpDebug',"message: $message\n". - print_r($parameters,TRUE)."\n",FILE_APPEND); + file_put_contents('/var/ywww/debug/phpDebug',"message: $message\n",FILE_APPEND); + if ($code=='AWS.InvalidParameterValue' && strpos($message,"for ItemId.")>0) { + // Check for common problem and try to fix... + $spd=$parameters['ItemId']; + if (strpos($spd,'/')>0) { + $isbnMaybe=substr($spd,0,strpos($spd,'/')); + $parameters['ItemId']=$isbnMaybe; + if (isset($parameters['Keywords'])) { + $parameters['Keywords']=urlencode($isbnMaybe); + } + file_put_contents('/var/ywww/debug/phpDebug',"retrying with $isbnMaybe\n",FILE_APPEND); + return doAmazonRequest($ext,$parameters,$try); + } + } if ($code=="") { file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$output\n",FILE_APPEND); }