hakanensari/vacuum

500 error with PA 5.0 and simple requests

onli opened this issue · 8 comments

onli commented

Hi! :)

I get 500 Internal server errors with simple requests against the PA (current vacuum version, so I assume PA 5.0). My request code looks like this:

result = @@api.search_items(
                    keywords: ["730143309936"],
                    resources: ['Images.Primary.Small',  'ItemInfo.ExternalIds', 'Offer.Listings.Price']
)

The response is:

#<HTTP::Response/1.1 500 Internal Server Error {"Server"=>"Server", "Date"=>"Wed, 18 Mar 2020 10:56:48 GMT", "Content-Type"=>"application/json", "Content-Length"=>"168", "Connection"=>"close", "X-Amzn-Requestid"=>"15ca1023-ed16-4bf4-aa7a-35f770bea65d", "Vary"=>"Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent", "X-Amz-Rid"=>"W7HW9JYDNGK1D150MS84"}>

I added the three debug outputs as shown in the readme, and get:

"{\"PartnerTag\":\"...\",\"PartnerType\":\"Associates\",\"Keywords\":[\"730143309936\"],\"Resources\":[\"Images.Primary.Small\",\"ItemInfo.ExternalIds\",\"Offer.Listings.Price\"]}"
{"host"=>"webservices.amazon.de", "x-amz-date"=>"20200318T105648Z", "x-amz-content-sha256"=>"...", "authorization"=>"AWS4-HMAC-SHA256 Credential=.../20200318/eu-west-1/ProductAdvertisingAPI/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=...", "x-amz-target"=>"com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems", "content-encoding"=>"amz-1.0", "content-type"=>"application/json; charset=utf-8"}
"https://webservices.amazon.de/paapi5/searchitems"

I'm completely aware that it's possible it's just a bug on Amazon's side, and it might even be account specific, but maybe it is caused by something uncommon in the request vacuum is producing and could be avoided? Is this working for everyone else?

Have you tried asking Amazon Associate support?

Your getting error number 500 and it seems like a server side error.

Usually problems related to this gem start with 4** error :)

onli commented

Thanks for your answer :) I tried to Amazon contact support, but didn't get a response (and also do not see a clear path to get real developer support).

I was hesitant assuming vacuum is at fault here. But I checked a bit more, changed access keys, tried around and now know: If I make the same request with the scratchpad everything is working just fine. That is what makes me assume that the error really is somewhere in the interaction between vaccum and PA.

Thanks for raising your concerns. Let's see if we can figure this out...

Based on a test for this method:
https://github.com/hakanensari/vacuum/blob/master/test/vacuum/test_request.rb#L39

It doesn't seem that we expect array as a value in keywords. Maybe try changing it to just a string?
Like this:

search_items(
                    keywords: "730143309936",
                    resources: ['Images.Primary.Small',  'ItemInfo.ExternalIds', 'Offer.Listings.Price']
)
onli commented

Oh, I missed that when switching from get_items to search_items (which I have to use because of the external id, ean, used here)! This changes things in a good direction. Instead of a 500 I now get a 400:

#<HTTP::Response/1.1 400 Bad Request {"Server"=>"Server", "Date"=>"Wed, 18 Mar 2020 14:37:09 GMT", "Content-Type"=>"application/json", "Content-Length"=>"233", "Connection"=>"close", "X-Amzn-Requestid"=>"9c65856f-a7c5-43c0-81a5-7d89adb54735", "Vary"=>"Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent", "X-Amz-Rid"=>"G680GFE732XQX5FE0ZGS"}>

I double checked that the access and secret key used is the same as in the scratchpad form.

How about partner_tag and marketplace? There is a chance you forgot to provide those :)

request = Vacuum.new(marketplace: 'US',
                     access_key: '<ACCESS_KEY>',
                     secret_key: '<SECRET_KEY>',
                     partner_tag: '<PARTNER_TAG>')
onli commented

Definitely ;)

marketplace is 'DE', partner_tag also matches.

But you got the right idea! I had a typo in the parameters:

['Images.Primary.Large',  'ItemInfo.ExternalIds', 'Offer.Listings.Price']

is not

['Images.Primary.Large',  'ItemInfo.ExternalIds', 'Offer**s**.Listings.Price']

And the initial error was just the [] around the keyword.

Thanks for your support! Sorry that it was an error on my end. Maybe there is a way to catch user errors like this in the gem?

PS: If you can take part in the github sponsor thingie I would add a bit for as long as my project uses this lib.

@onli great to hear that everything works for you.

@hakanensari We agreed to keep implementation of this gem minimal with our last rewrite. But amazon returning 500 for some typos - seems really cryptic and hard to reason with.

I will add some input validation to avoid these issues.

I will add some input validation to avoid these issues.

@skatkov Sounds good. Yes, even Amazon's response body in this case is not helpful.

While I was at this, I noticed we could not log requests, so I went ahead and fixed this by exposing the chainable methods of HTTP. More here.