打开https时出现EOF错误

发布于 2024-12-06 22:25:23 字数 2312 浏览 0 评论 0原文

我一直在尝试使用 facebook graph api,尽管 ruby​​ 在打开 api url 时引发 EOFError (https://graph.facebook.com/.....) 我正在使用 Ruby 1.8.6 和 Rails 2.2.2。 代码如下:

require 'uri'
require 'https'

access_token = open("https://graph.facebook.com/oauth/access_token?client_id=app_id&client_secret=app_secret&grant_type=client_credentials"){|f|
   f.read
}

出现以下错误:

end of file reached

/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:133:in `sysread'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/timeout.rb:62:in `timeout'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/timeout.rb:93:in `timeout'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:126:in `readline'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:2022:in `read_status_line'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:2011:in `read_new'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:1050:in `request'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:248:in `open_http'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:543:in `start'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:242:in `open_http'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:162:in `catch'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:518:in `open'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:30:in `open'
app/models/news_release.rb:75:in `post_to_facebook_wall'

我彻底用谷歌搜索并搜索了此错误,并尝试了 httpparty、mechanism、fb_graph 和 koala 等。 然而,这些都会引发同样的错误。 ruby-1.8.6 或 open-uri 似乎有错误,但我不想升级 ruby​​。

有什么想法吗? 提前致谢。

I've been trying to use facebook graph api, though ruby raise EOFError when open api url (https://graph.facebook.com/.....)
I'm using Ruby 1.8.6 and Rails 2.2.2.
The code is as follows:

require 'uri'
require 'https'

access_token = open("https://graph.facebook.com/oauth/access_token?client_id=app_id&client_secret=app_secret&grant_type=client_credentials"){|f|
   f.read
}

Got following error:

end of file reached

/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:133:in `sysread'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/timeout.rb:62:in `timeout'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/timeout.rb:93:in `timeout'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:126:in `readline'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:2022:in `read_status_line'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:2011:in `read_new'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:1050:in `request'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:248:in `open_http'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:543:in `start'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:242:in `open_http'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:162:in `catch'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:518:in `open'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:30:in `open'
app/models/news_release.rb:75:in `post_to_facebook_wall'

I thoroughly googled and searched about this error and tried such as httpparty, mechanism, fb_graph, and koala.
However those raise same efoerror.
It seems that there is a bug with ruby-1.8.6 or open-uri, but I don't want to upgrade ruby.

Any ideas?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喵星人汪星人 2024-12-13 22:25:23

看起来 ssl 失败,因为您没有填写参数。试试这样:

require 'open-uri'

app_id = 'fill_me_out'
app_secret = 'fill_me_out_too'
url = "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}&client_secret=#{app_secret}&grant_type=client_credentials"
access_token = open(url).read

It looks like ssl is failing because you didn't fill out the parameters. Try it like this:

require 'open-uri'

app_id = 'fill_me_out'
app_secret = 'fill_me_out_too'
url = "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}&client_secret=#{app_secret}&grant_type=client_credentials"
access_token = open(url).read
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文