8

I've downloaded Amazon's Marketplace SDK and I'm trying out one of the samples in the samples dir. However, I'm getting an exception with the following details whenever I try it:

Caught Exception: Internal Error
Response Status Code: 0
Error Code: 
Error Type: 
Request ID: 
XML: RequestId: , ResponseContext: , Timestamp: 
ResponseHeaderMetadata: 

I have got CURL enabled with SSL as well. What am I doing wrong?

starball
  • 20,030
  • 7
  • 43
  • 238
Ali
  • 261,656
  • 265
  • 575
  • 769
  • 1
    I had a similar problem when the server simply couldn't access external pages. Aside from cURL being enabled, have you confirmed that cURL actually works? – tvkanters Jan 13 '13 at 14:07
  • @TVK Well, I'm able to use Facebook's API on the same server, so I think it should be working. How else can I verify that its working? – Ali Jan 13 '13 at 14:14
  • 1
    I personally like to use this function: http://pastebin.com/PwpFFBW7 To test the connection, type `echo curl('http://example.com');` If Facebook's API is working then perhaps it's a connection problem between the PHP server and Amazon server. Can you ping Amazon from the server? – tvkanters Jan 13 '13 at 14:19
  • @TVK I just tried that, using `curl('http://google.com');`, got correct response, i.e: ` 301 Moved

    301 Moved

    The document has moved here. `
    – Ali Jan 13 '13 at 14:23
  • So curl seems to be working.? – Ali Jan 13 '13 at 14:24
  • 1
    Ah, but if I change the url to `https://mws.amazonservices.com`, then I get `false` as response, same with `https://google.com`. So the issue is with https urls? Any ideas? – Ali Jan 13 '13 at 14:25
  • Seems like SSL is the problem indeed. I'm not quite sure what the cause of that is, but it could be related to the server settings or the points the request passes. E.g., a TMG server. – tvkanters Jan 13 '13 at 14:27
  • @TVK Well, turning off `CURLOPT_SSL_VERIFYPEER` has fixed the issue for now. If any ideas, you can submit an answer and I'll accept it. Thanks for the help. – Ali Jan 13 '13 at 14:31
  • 3
    Have a look here - http://curl.haxx.se/docs/caextract.html - basically, cURL doesn't come with a good list of CA's to check against. – Ja͢ck Jan 22 '13 at 00:03

3 Answers3

16

This answer is for future reference. For in-depth troubleshooting, see comments on the question.

The empty response indicates a failed connection to the Amazon server. In this case, HTTP worked fine, but HTTPS did not. As turning off CURLOPT_SSL_VERIFYPEER in the cURL settings solved the issue, it appears that the Amazon server was not using a valid SSL certificate.

Having CURLOPT_SSL_VERIFYPEER turned on checks if the requested host has a valid certificate and lets cURL return false if it doesn't. When CURLOPT_SSL_VERIFYPEER is off, invalid certificates (e.g., self-signed) are accepted and return the regular response.

tvkanters
  • 3,519
  • 4
  • 29
  • 45
  • Thanks for the help. By the way, are you familiar with MWS? – Ali Jan 13 '13 at 14:45
  • This helped me immensely! I added that to the performRequest() function of the Client.php of the Amazon MWS PHP Feed Library and finaly got a response! Thanks! – jmk Jun 04 '13 at 15:08
2

For future reference. In the new version of the SDK the options are referenced in the client.php as follows

private function getDefaultCurlOptions() {
    return array (
      CURLOPT_POST => true,
      CURLOPT_USERAGENT => $this->config['UserAgent'],
      CURLOPT_VERBOSE => true,
      CURLOPT_HEADERFUNCTION => array ($this, 'headerCallback'),
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_SSL_VERIFYPEER => true,
      CURLOPT_SSL_VERIFYHOST => 2
    );
  }

setting

CURLOPT_SSL_VERIFYPEER => false,

did the trick in my case. As I am not a security expert, however, no recommendation from this point of view. At least its working and you are probably not loosing 1 whole day as I did.

1

I experienced a very similar connection issue with Amazon. It was the sample files bundled with the Amazon php api, which contain a following configuration array:

$config = array (
  'ServiceURL' => $serviceUrl,
  'ProxyHost' => null,
  'ProxyPort' => -1,
  'MaxErrorRetry' => 3,
);

and if this is copied over and not modified

'ProxyPort' => -1,

will result in an attempt to connect through a proxy port -1 which will of course fail (issue tracked by checking curl error). I hope this helps.

dadasign
  • 408
  • 4
  • 7