# HG changeset patch # User Charlie Root # Date 1546628723 18000 # Node ID 633402a4995d5e0a9e9ffe176c17888d7eaed560 # Parent e570b199108b03378f290ffb64fd70f7a31f669b try to fix a common lookup error diff -r e570b199108b -r 633402a4995d xml/doAmazonRequest.inc --- 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); }