我试图使用HTTParty在一个Sinatra应用程序中执行一个HTTP请求。我可以在Sinatra应用程序之外成功地执行相同的请求,但是当它在应用程序中执行时,我总是得到相同的异常:
2013-09-08T16:04:44.738207+00:00 app[web.1]: [2013-09-08 16:04:44] ERROR NoMethodError: undefined method 'status=' for #<HTTParty::Response:0x007f17c050dd70>`
2013-09-08T16:04:44.837777+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:225:in `status'
2013-09-08T16:04:44.936617+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:1080:in `handle_exception!'
2013-09-08T16:04:45.039513+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:1062:in `block in dispatch!'
2013-09-08T16:04:45.139212+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `block in invoke'
2013-09-08T16:04:45.238557+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `catch'
2013-09-08T16:04:45.338714+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:1041:in `invoke'
2013-09-08T16:04:45.437306+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:1062:in `rescue in dispatch!'
2013-09-08T16:04:45.536146+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.3/lib/sinatra/base.rb:1069:in `dispatch!'堆栈跟踪的其余部分与此无关。我确信请求成功地结束了。执行请求的确切代码如下:
@response = HTTParty.get("https://foursquare.com/oauth2/access_token",
:query => {:client_id => settings.client_id,
:client_secret => settings.client_secret,
:grant_type => "authorization_code",
:redirect_uri => settings.redirect_uri,
:code => @code})看起来辛纳屈试图挽救一些异常,然后对我在HTTParty中执行的HTTP请求的结果调用一个HTTParty方法。
所以,很高兴了解到底发生了什么,为什么西纳屈会这样做。
非常感谢您的答复。
发布于 2013-09-08 16:46:40
问题是用于存储响应的变量的名称:@response是为Sinatra的内部目的保留的。感谢@eljojo为我指出了这一点。
https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L858
https://stackoverflow.com/questions/18686086
复制相似问题