OpenURI :: HTTPError:403 Forbidden

时间:2010-02-21 13:17:17

标签: ruby-on-rails http-status-code-403

我正在使用wikipedia-api插件从维基百科获取内容的页面。 从某些日子开始,当我尝试获取内容时,我收到此错误:

  page = Wikipedia.find_by_titles('Foo')
OpenURI::HTTPError: 403 Forbidden
    from /usr/lib/ruby/1.8/open-uri.rb:277:in `open_http'
    from /usr/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
    from /usr/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
    from /usr/lib/ruby/1.8/open-uri.rb:162:in `catch'
    from /usr/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
    from /usr/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
    from /usr/lib/ruby/1.8/open-uri.rb:518:in `open'
    from /usr/lib/ruby/1.8/open-uri.rb:30:in `open'
    from /home/luca/Programming/nerto_5/vendor/plugins/wikipedia-api/lib/mediawiki.rb:139:in `get_xml'
那是什么?

我该怎么办?

感谢

2 个答案:

答案 0 :(得分:6)

我已经解决了改变

Hpricot.XML(open(url))

  Hpricot.XML(open(url, 'User-Agent' => 'ruby'))

在mediawiki.rb文件中

答案 1 :(得分:3)

是的,它有效。

Nokogiri 403 Forbidden问题同样如此

doc = Nokogiri :: HTML(开放(网站,'User-Agent'=>'ruby'))