net/http.rb:560:in `initialize': getaddrinfo: 名称或服务未知(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
我正在尝试执行 oauth 所做的事情,试图了解如何使用授权标头。我也收到以下错误。我正在尝试连接到 linkedin API。
/usr/lib/ruby/1.8/net/http.rb:560:in 'initialize': getaddrinfo: 名称或服务未知 (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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“名称或服务未知”是套接字级错误,通常指向无效的 IP 地址/DNS 主机名或未注册的端口名称(例如
telnet the.host.name 服务
,其中service
不是已注册的服务名称。)检查
CONNECT_URL
是否包含有效的 URL。编辑:我不是 Ruby 程序员,但我不介意打赌
Net::HTTP.new
需要一个主机名(例如 www.facebook.com)第一个参数,不是完整的 URL(例如 www.facebook.com/login.php?method=oauth)。"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
whereservice
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).当您没有 Internet 连接时,您也会收到此错误,因为 DNS 查找通常是使用主机名建立 TCP 连接时发生的第一件事。
拔下网络电缆并尝试:
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: