2011-11-02 69 views
0

我們使用的是Rails 3.0.6,Ruby 1.8.7。使用Ruby訪問已發佈的Google文檔電子表格時的HTTPInternalServerError

代碼:

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> 

的反應表明,它是谷歌的服務器錯誤,但我們無法想象它的嗆這樣的程序調用。

該電子表格已發佈,因此任何人都可以訪問該鏈接。

我們做錯了什麼?

回答

0

試試這個

需要 '網/ HTTPS'

URL =「https://docs.google.com/spreadsheet/pub?hl=en_US & HL = EN_US &鍵= 0Ala -Qy5xnYGFdE83bng2RC0yTVFVUDVfNW5NV2hwc1E &輸出= 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 
+0

真棒,謝謝! – Crashalot

相關問題