使用 Ruby 访问已发布的 Google Docs 电子表格时出现 HTTPInternalServerError

发布于 2024-12-13 08:06:27 字数 2840 浏览 1 评论 0原文

我们使用的是 Rails 3.0.6,Ruby 1.8.7。

代码:

url = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0Ala-Qy5xnYGFdE83bng2RC0yTVFVUDVfNW5NV2hwc1E&output=csv'
uri = URI.parse url
req = Net::HTTP::Get.new uri.path

http = Net::HTTP.new uri.host, uri.port
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
response = http.request req
puts response

输出:

#<Net::HTTPInternalServerError:0xc80edb8>
<!DOCTYPE html><html lang="en">
     <head>
         <meta name="description" content="Web word processing, presentations and spreadsheets" />
         <link rel="shortcut icon" href="//www.google.com/images/icons/product/spreadsheets-16.png" />
         <title>Google Docs Error</title>
         <style type="text/css">body {background-color: #fff; font-family: Arial,sans-serif; font-size: 13px; margin: 0; padding: 0;}a, a: link, a: visited {color: #112ABB;}</style>
         <style type="text/css">.errorMessage {font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style>
      </head>
      <body>
          <div style="padding: 8px;">
              <a href="//docs.google.com/">
                  <img border="0" id="docs-logo" src="//ssl.gstatic.com/docs/common/logo/docs_logo.gif" width="122" border="0" alt="">
              </a>
          </div>
          <center>
              <table>
                  <tr>
                      <td>
                          <p style="padding-top: 15px">Google Docs has encountered a server error. If reloading the page doesn't help, please <a href="http://docs.google.com/support/bin/request.py?hl=en&ctx=docs&contact_type=server_error">contact us</a>.</p>
                          <p>We&#39;re sorry, a server error occurred. Please wait a bit and try reloading your spreadsheet.<br>
                             To discuss this or other issues, visit the <a href="http://www.google.com/support/forum/p/Google+Docs?hl=en">Google Docs Help forum</a>. To see the list of known problems, check the <a href="http://docs.google.com/support/bin/static.py?hl=en&page=known_issues.cs">Google Docs Known Issues page</a>.</p>
                          <p><br><b>Sorry, and thanks for your help!</b><br>
                             <i>- The Google Docs Team</i></p>
                     </td>
                 </tr>
            </table>
        </center>
    </body>
</html>

响应表明这是 Google 服务器错误,但我们无法想象它会因这样的例行调用而阻塞。

该电子表格已发布,任何知道该链接的人都可以访问。

我们做错了什么吗?

We're on Rails 3.0.6, Ruby 1.8.7.

Code:

url = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0Ala-Qy5xnYGFdE83bng2RC0yTVFVUDVfNW5NV2hwc1E&output=csv'
uri = URI.parse url
req = Net::HTTP::Get.new uri.path

http = Net::HTTP.new uri.host, uri.port
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
response = http.request req
puts response

Output:

#<Net::HTTPInternalServerError:0xc80edb8>
<!DOCTYPE html><html lang="en">
     <head>
         <meta name="description" content="Web word processing, presentations and spreadsheets" />
         <link rel="shortcut icon" href="//www.google.com/images/icons/product/spreadsheets-16.png" />
         <title>Google Docs Error</title>
         <style type="text/css">body {background-color: #fff; font-family: Arial,sans-serif; font-size: 13px; margin: 0; padding: 0;}a, a: link, a: visited {color: #112ABB;}</style>
         <style type="text/css">.errorMessage {font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style>
      </head>
      <body>
          <div style="padding: 8px;">
              <a href="//docs.google.com/">
                  <img border="0" id="docs-logo" src="//ssl.gstatic.com/docs/common/logo/docs_logo.gif" width="122" border="0" alt="">
              </a>
          </div>
          <center>
              <table>
                  <tr>
                      <td>
                          <p style="padding-top: 15px">Google Docs has encountered a server error. If reloading the page doesn't help, please <a href="http://docs.google.com/support/bin/request.py?hl=en&ctx=docs&contact_type=server_error">contact us</a>.</p>
                          <p>We're sorry, a server error occurred. Please wait a bit and try reloading your spreadsheet.<br>
                             To discuss this or other issues, visit the <a href="http://www.google.com/support/forum/p/Google+Docs?hl=en">Google Docs Help forum</a>. To see the list of known problems, check the <a href="http://docs.google.com/support/bin/static.py?hl=en&page=known_issues.cs">Google Docs Known Issues page</a>.</p>
                          <p><br><b>Sorry, and thanks for your help!</b><br>
                             <i>- The Google Docs Team</i></p>
                     </td>
                 </tr>
            </table>
        </center>
    </body>
</html>

The response suggests it's a Google server error, but we can't imagine it's choking on such a routine call.

The spreadsheet is published and thus accessible to anyone with the link.

Are we doing something wrong?

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

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

发布评论

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

评论(1

笨死的猪 2024-12-20 08:06:27

尝试一下

require 'net/https'

url = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0Ala-Qy5xnYGFdE83bng2RC0yTVFVUDVfNW5NV2hwc1E&output=csv'

uri = URI.parse url

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(uri.request_uri)

response = http.request(request)
puts response.body

Give this a try

require 'net/https'

url = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0Ala-Qy5xnYGFdE83bng2RC0yTVFVUDVfNW5NV2hwc1E&output=csv'

uri = URI.parse url

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(uri.request_uri)

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