Getting internal error with Response Status Code 0 on Amazon Marketplace API Requests
Asked Answered
V

3

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?

Vmail answered 13/1, 2013 at 13:59 Comment(9)
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?Arraignment
@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?Vmail
I personally like to use this function: 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?Arraignment
@TVK I just tried that, using curl('http://google.com');, got correct response, i.e: <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML>Vmail
So curl seems to be working.?Vmail
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?Vmail
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.Arraignment
@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.Vmail
Have a look here - curl.haxx.se/docs/caextract.html - basically, cURL doesn't come with a good list of CA's to check against.Schwann
A
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.

Arraignment answered 13/1, 2013 at 14:37 Comment(2)
Thanks for the help. By the way, are you familiar with MWS?Vmail
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!Lise
S
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.

Sagunto answered 30/4, 2017 at 11:45 Comment(0)
C
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.

Chord answered 27/11, 2013 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.