2013-06-27 73 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/