开发者

net/http.rb:560:in `initialize': getaddrinfo: Name or service not known (SocketError)

@@timestamp = nil

def generate_oauth_url
  @@timestamp = timestamp
  url = CONNECT_URL + REQUEST_TOKEN_PATH + "&oauth_callback=#{OAUTH_CALLBACK}&oauth_consumer_key=#{OAUTH_CONSUMER_KEY}&oauth_nonce=#{NONCE}    &oauth_signature_method=#{OAUTH_SIGNATURE_METHOD}&oauth_timestamp=#{@@timestamp}&oauth_version=#{OAUTH_VERSION}"
  puts url
  url             
end

def sign(url)
  Base64.encode64(HMAC::SHA1.digest((NONCE + url), OAUTH_CONSUMER_SECRET)).strip
end

def get_request_token
  url = generate_oauth_url
  signed_url = sign(url)          
  request = Net::HTTP.new((CONNECT_URL + REQUEST_TOKEN_PATH),80)
  puts request.inspect
  headers = { "Authorization" => "Authorization: OAuth oauth_nonce = #{NONCE}, oauth_callback = #{OAUTH_CALLBACK}, oauth_signature_meth    od = #{OAUTH_SIGNATURE_METHOD}, oauth_timestamp=#{@@timestamp}, oauth_consumer_key = #{OAUTH_CONSUMER_KEY}, oauth_signature = #{signed_url}, oauth_versio    n = #{OAUTH_VERSION}" }

  request.post(url, nil,headers)                  
end

def timestamp
  Time.开发者_开发问答now.to_i
end

I am trying to do what oauth does in an attempt to understand how to use the Authorization headers. I am also getting the following error. I am trying to connect to the linkedin API.

/usr/lib/ruby/1.8/net/http.rb:560:in 'initialize': getaddrinfo: Name or service not known (SocketError)

I would really appreciate it if someone could nudge me in the right direction.


"Name or service not known" is a socket-level error which usually points to either an invalid IP address/DNS hostname, or an unregistered port name (e.g. telnet the.host.name service where service is not a registered service name.)

Check that CONNECT_URL holds a valid URL.

EDIT: I'm not a Ruby programmer, but I wouldn't mind betting that Net::HTTP.new requires a hostname (e.g. www.facebook.com) as the first argument, not a complete URL (e.g. www.facebook.com/login.php?method=oauth).


You also get this error when you have no internet connection since a DNS lookup is often the first thing that happens when establishing a TCP connection using a hostname.

Unplug your network cable and try:

Socket.getaddrinfo("www.example.com", "http")
# => SocketError: getaddrinfo: nodename nor servname provided, or not known
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜