OpenURI - XML 源上的 500 内部服务器错误

发布于 2024-11-05 08:12:07 字数 788 浏览 0 评论 0原文

我正在尝试阅读斯坦福 ecorner XML:

open("http://ecorner.stanford.edu/RecentlyAdded.xml")

但遇到以下错误消息:

OpenURI::HTTPError: 500 Internal Server Error
    from /usr/local/lib/ruby/1.8/open-uri.rb:277:in `open_http'
    from /usr/local/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
    from /usr/local/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
    from /usr/local/lib/ruby/1.8/open-uri.rb:162:in `catch'
    from /usr/local/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
    from /usr/local/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
    from /usr/local/lib/ruby/1.8/open-uri.rb:518:in `open'
    from /usr/local/lib/ruby/1.8/open-uri.rb:30:in `open'
    from (irb):65
    from :0

我相信,但我可能是错的,这是因为我需要登录才能使用提要。

我可以使用任何解决方法吗?

I'm trying to read Stanford ecorner XML:

open("http://ecorner.stanford.edu/RecentlyAdded.xml")

but am running into the following error message:

OpenURI::HTTPError: 500 Internal Server Error
    from /usr/local/lib/ruby/1.8/open-uri.rb:277:in `open_http'
    from /usr/local/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
    from /usr/local/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
    from /usr/local/lib/ruby/1.8/open-uri.rb:162:in `catch'
    from /usr/local/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
    from /usr/local/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
    from /usr/local/lib/ruby/1.8/open-uri.rb:518:in `open'
    from /usr/local/lib/ruby/1.8/open-uri.rb:30:in `open'
    from (irb):65
    from :0

I believe, but I could be wrong, it's because I would need to be logged in to use the feed.

Any workaround I could use?

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

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

发布评论

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

评论(2

贵在坚持 2024-11-12 08:12:07

如果未登录,您应该收到 HTTP 响应代码 401 Unauthorized 而不是 500。我尝试在浏览器中打开该网站,结果有效。事实证明,他们的网络服务器不喜欢缺少用户代理,因此如果您添加 open-uri 即可:

>> require 'open-uri' 
#=> true
>> open("http://ecorner.stanford.edu/RecentlyAdded.xml", 'User-Agent' => 'ruby') 
#=> #<File:/var/folders/H9/H9qnar1yGZqBrWFGuTE0RU+++TI/-Tmp-/open-uri20110505-25566-zsc3pd-0>

In case of not being logged in you should get an HTTP response code of 401 Unauthorized and not 500. I tried to open the site in the browser, which works. Turns out their web server doesn't like missing user agents, so if you add that open-uri works:

>> require 'open-uri' 
#=> true
>> open("http://ecorner.stanford.edu/RecentlyAdded.xml", 'User-Agent' => 'ruby') 
#=> #<File:/var/folders/H9/H9qnar1yGZqBrWFGuTE0RU+++TI/-Tmp-/open-uri20110505-25566-zsc3pd-0>
瞄了个咪的 2024-11-12 08:12:07

这对我有用:

require 'open-uri'
require 'nokogiri'

doc = Nokogiri::XML(open('http://ecorner.stanford.edu/RecentlyAdded.xml'))
puts doc.search('title').map{ |n| n.text }

>> Recently Added STVP Entrepreneurship Corner Materials
>> STVP Entrepreneurship Corner
>> Podcast: Developing Products that Save Lives - Richard Scheller (Genentech)
>> Podcast: How to Build Instant Connections - Ori Brafman (Author)
>> Podcast: A New Vision for Capital Markets - Barry Silbert (SecondMarket)
>> Podcast: Effective Models for Sustainable Growth - Jennifer Morris (Conservation International)

请注意,您遇到了 500 范围的错误。这意味着他们的服务器正在运行,但功能足以承认该问题。如果您收到 400 范围的错误,他们会出于某种原因拒绝您访问内容,所以我怀疑问题出在身份验证或您这边的任何问题上。

This is working for me:

require 'open-uri'
require 'nokogiri'

doc = Nokogiri::XML(open('http://ecorner.stanford.edu/RecentlyAdded.xml'))
puts doc.search('title').map{ |n| n.text }

>> Recently Added STVP Entrepreneurship Corner Materials
>> STVP Entrepreneurship Corner
>> Podcast: Developing Products that Save Lives - Richard Scheller (Genentech)
>> Podcast: How to Build Instant Connections - Ori Brafman (Author)
>> Podcast: A New Vision for Capital Markets - Barry Silbert (SecondMarket)
>> Podcast: Effective Models for Sustainable Growth - Jennifer Morris (Conservation International)

Note that you got a 500-range error. That means their server is acting up, but is functional enough to admit the problem. If you got a 400-range error they'd be refusing you access to the content for some reason, so I doubt the problem is authentication or anything on your side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文