phoet / asin

:books: :package: Amazon Simple INterface - Support for ItemLookup, SimilarityLookup, Search, BrowseNode and Cart Operations
http://asin.herokuapp.com/
167 stars 59 forks source link

Latest Amazon changes to product API seemed to result in errors #39

Closed ianlin0126 closed 10 years ago

ianlin0126 commented 10 years ago

I'm using the asin gem (https://github.com/phoet/asin) to make requests to Amazon Product API.

It has been working well for a whole year but a few days ago without making any changes I started noticing the same product API requests now return the following error:

<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2011-08-01/"><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message></Error><RequestId>314b6504-8845-43a1-bdf6-53b02bbc974b</RequestId></ItemLookupErrorResponse>'
RuntimeError: request failed with response-code='403'
    from /usr/local/rvm/gems/ruby-1.9.3-p484/gems/asin-2.0.1/lib/asin/client.rb:264:in `call'
    from /usr/local/rvm/gems/ruby-1.9.3-p484/gems/asin-2.0.1/lib/asin/client.rb:55:in `lookup'
    from (irb):5
    from /usr/local/rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
    from /usr/local/rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
    from /usr/local/rvm/gems/ruby-1.9.3-p484/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

The original request still works, so I'm assuming that some changes on Amazon product API made the asin gem incompatible:

http://webservices.amazon.com/onca/xml?AWSAccessKeyId=<my-key>&AssociateTag=<my-tag>&Keywords=apple&Operation=ItemSearch&ResponseGroup=ItemAttributes&SearchIndex=UnboxVideo&Service=AWSECommerceService&Timestamp=2014-07-25T23%3A57%3A23Z&Version=2011-08-01&Signature=<hash>
phoet commented 10 years ago

i can't see a problem

response = @client.search Keywords: 'apple', SearchIndex: :UnboxVideo
response.first.asin # => B003V2MC78
ianlin0126 commented 10 years ago

I tried debugging this and found in client.rb 255 the HTTPI.get(url) seems to be causing trouble for me: HTTPI GET request to webservices.amazon.com (excon)

 => #<HTTPI::Response:0x007f93c6089a38 @code=403, @headers={"Date"=>"Sat, 26 Jul 2014 17:14:21 GMT", "Server"=>"Server", "Vary"=>"Accept-Encoding,User-Agent", "Connection"=>"close", "Transfer-Encoding"=>"", "Content-Type"=>"text/plain"}, @raw_body="<?xml version=\"1.0\"?>\n<ItemLookupErrorResponse xmlns=\"http://ecs.amazonaws.com/doc/2011-08-01/\"><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message></Error><RequestId>d13e229f-5561-4807-9dae-00d11331735f</RequestId></ItemLookupErrorResponse>"> 

My httpi is v2.2.4, not sure if this is the problem.

However, if I use HTTParty it doesn't throw the same error. Was wondering if this occurs to you as well?

kurtfunai commented 10 years ago

I seem to be getting the proper response with HTTPI from what I can tell

response = @client.search Keywords: 'apple', SearchIndex: :UnboxVideo
DEBUG -- : calling with params={:Keywords=>"apple", :SearchIndex=>:UnboxVideo, :Operation=>:ItemSearch}
DEBUG -- : HTTPI GET request to webservices.amazon.com (httpclient)
DEBUG -- : got response='<?xml version="1.0" ?> #etc...
# ...
response.first.asin
=> "B003V2MC78"

Here's my version of httpi

gem list | grep httpi   
httpi (2.0.0, 1.1.1)
ianlin0126 commented 10 years ago

Thanks guys! I think it's the newer version of httpi causing problem. Using 2.0.0 works for me too

kurtfunai commented 10 years ago

No problemo :smiley: :+1:

Merovex commented 9 years ago

This is not fixed. I can't install httpi v2.0.0; so now i can't use this gem.

phoet commented 9 years ago

@Merovex it's running with httpi 2.3.0 as well. is that an option for you?

Merovex commented 9 years ago

I fixed the ability to install the httpi:2.0.0 gem. But, I get a 403 error via the gem...but the URL works fine in the browser.

Merovex commented 9 years ago

I just forced the gem (see below) and it works fine. The default httpi gem is 2.3.0, I also have 2.1.0 installed. So, I submit it does not work with 2.3.0.

require 'rubygems' gem 'httpi', "2.0.0" require 'asin'

phoet commented 9 years ago

@Merovex what ruby version are you running on?

Merovex commented 9 years ago

ruby-2.0.0-p481, but I don't see anything that suggests a conflict b/w httpi and that version.

On Wed, Dec 17, 2014 at 11:04 AM, Peter Schröder notifications@github.com wrote:

@Merovex https://github.com/Merovex what ruby version are you running on?

— Reply to this email directly or view it on GitHub https://github.com/phoet/asin/issues/39#issuecomment-67344457.

Ben Wilson "A belief, no matter how sincere, if not reflected in reality isn’t a belief; it’s a delusion."

kez commented 9 years ago

If you're looking for a quick fix, you can "gem 'curb'" in your Gemfile and "skip over" trying to resolve the problem with HTTPI (I also had the above).

phoet commented 9 years ago

i can't find anything in HTTPI that would have any influence on this. my assumption is that some HTTP library changed the way it treats parameters (or whitespace) and thus there is a malformed signature.

if you can provide any further information post it here.

this is the amazon troubleshooting guide, just in case...