开发者

RAILS EXCEPTION: undefined method `keys' for nil:NilClass

开发者 https://www.devze.com 2023-03-19 06:23 出处:网络
I can\'t figure out why in the following line of code res = https.get(url开发者_JAVA技巧, nil) The application stops and give me the following exception:

I can't figure out why in the following line of code

res = https.get(url开发者_JAVA技巧, nil)

The application stops and give me the following exception:

undefined method `keys' for nil:NilClass

The strange things is that this error happens only in my development enviroment, when I put the application online (heroku), everyhthing work like a charm.

That above line of code, use this inclusion:

require 'net/https'

Is anybody able to explain me why ?

Tnx


If you don't want to pass any headers just use:

res = https.get(url, {})


in the documentation for Net::HTTP this method definition is

def get(path, initheader = {}, dest = nil, &block) # :yield: +body_segment+
  res = nil
  if HAVE_ZLIB
    unless  initheader.keys.any?{|k| k.downcase == "accept-encoding"}
      initheader["accept-encoding"] = "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
      @compression = true
....

in your code initheader is nil so error happens on line four initheader.keys It may work fine on heroku because there is if HAVE_ZLIB which can be faulse so code is skipped.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号