HTTParty force_encoding:encode_with_ruby_encoding

时间:2017-05-15 16:20:12

标签: httparty

我最近从0.14.0更新到版本0.15.2,当我尝试执行#delete时我收到了以下的堆栈跟踪:

NoMethodError: undefined method `force_encoding' for nil:NilClass
from /Users/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty/request.rb:280:in `encode_with_ruby_encoding'
from /Users/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty/request.rb:316:in `_encode_body'
from /Users/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty/request.rb:322:in `encode_body'
from /Users/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty/request.rb:350:in `handle_response'
from /Users//.rben`enter code here`v/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty/request.rb:158:in `perform'
from /Users/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty.rb:563:in `perform_request'
from /Users/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty.rb:520:in `delete'
from /Users/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/httparty-0.15.1/lib/httparty.rb:617:in `delete'

我恢复到版本0.14.0并且问题不会持续存在。我是Ruby的初学者,我不确定这条消息的含义。

任何帮助都会感激不尽。

1 个答案:

答案 0 :(得分:0)

如果查看https://github.com/jnunemaker/httparty/blob/e9f4624c1172120bbd39ddc636620a24fc9386b1/lib/httparty/request.rb#L278,您可以看到堆栈跟踪中引用的force_encoding方法。

似乎响应没有正文,因此在nil对象上调用此方法,这会导致错误。这似乎是HTTParty中的一个错误。如果您可以找出一致地产生此问题的复制步骤,您可以为HTTParty人员打开一个github问题,以便进一步研究它。