2013-06-27 70 views
0

我最近从ruby-aaws宝石移到asin宝石,这是很容易使用和理解。但是,我遇到了一个非常奇怪的问题,它会导致特定查询的搜索失败,并且只会在heroku上发生。红宝石asin宝石搜索失败heroku

我的代码如下:

require 'asin' 

client = ASIN::Client.instance 

client.search(:Keywords => "Shark Tale", :SearchIndex => :UnboxVideo, :ResponseGroup => :ItemAttributes) 

当这个运行在我的本地盒,它可以完美运行没有问题。但是,当我在heroku上运行此操作时,我看到以下错误日志:

REXML::ParseException: #<NoMethodError: undefined method `[]' for nil:NilClass> 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/baseparser.rb:340:in `pull_event' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/baseparser.rb:183:in `pull' 
/app/vendor/bundle/ruby/2.0.0/gems/crack-0.4.0/lib/crack/xml.rb:203:in `parse' 
/app/vendor/bundle/ruby/2.0.0/gems/crack-0.4.0/lib/crack/xml.rb:235:in `parse' 
/app/vendor/bundle/ruby/2.0.0/gems/asin-1.1.2/lib/asin/client.rb:375:in `call' 
/app/vendor/bundle/ruby/2.0.0/gems/asin-1.1.2/lib/asin/client.rb:197:in `search' 
(irb):223:in `irb_binding' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/workspace.rb:86:in `eval' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/workspace.rb:86:in `evaluate' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/context.rb:380:in `evaluate' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb.rb:492:in `block (2 levels) in eval_input' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb.rb:624:in `signal_status' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb.rb:489:in `block in eval_input' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/ruby-lex.rb:247:in `block (2 levels) in each_top_level_statement' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `loop' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `catch' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `each_top_level_statement' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb.rb:488:in `eval_input' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb.rb:397:in `block in start' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb.rb:396:in `catch' 
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/irb.rb:396:in `start' 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start' 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start' 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>' 
script/rails:6:in `require' 
script/rails:6:in `<main>' 
... 
Exception parsing 
Line: 1 
Position: 30315 
Last 80 unconsumed characters: 
Actor><Actor>Matthew Broderick</Actor><Actor>Patrick Warburton</Actor><Actor>J 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/baseparser.rb:439:in `rescue in pull_event' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/baseparser.rb:331:in `pull_event' 
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rexml/parsers/baseparser.rb:183:in `pull' 
from /app/vendor/bundle/ruby/2.0.0/gems/crack-0.4.0/lib/crack/xml.rb:203:in `parse' 
from /app/vendor/bundle/ruby/2.0.0/gems/crack-0.4.0/lib/crack/xml.rb:235:in `parse' 
from /app/vendor/bundle/ruby/2.0.0/gems/asin-1.1.2/lib/asin/client.rb:375:in `call' 
from /app/vendor/bundle/ruby/2.0.0/gems/asin-1.1.2/lib/asin/client.rb:197:in `search' 
from (irb):223 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start' 
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start' 
from /app/vendor/bundle/ruby/2.0.0/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>' 

这在Heroku的大约10次中失败了。我尝试了一些变化和下面的一些变化,成功的所有时间:

改变查询略有

client.search(:Keywords => "Shark Tales", :SearchIndex => :UnboxVideo, :ResponseGroup => :ItemAttributes) 

更改ResponseGroup

client.search(:Keywords => "Shark Tale", :SearchIndex => :UnboxVideo, :ResponseGroup => :Offers) 

有谁知道是什么引起的?

+0

的作者为2.0.0的解决方案看起来你从亚马逊获得格式不正确的XML(尽管这看起来不太可能)。你可以将ASIN日志级别设置为info并将输出发布到某处?特别是应该有一个消息,说“得到回应= ...”。像'ASIN :: Configuration.logger.level = Logger :: INFO'可能会这样做。 – georgebrock

回答

0

认识到我的本地盒子和heroku之间的差异是与红宝石版本。

我在本地箱,而我的Heroku的环境中使用1.9.3是2.0.0

这是从ASIN宝石 http://asin.herokuapp.com/