【问题标题】:Import CSV from Google Spreadsheet using Python使用 Python 从 Google 电子表格导入 CSV
【发布时间】:2022-02-04 18:02:06
【问题描述】:

当我在浏览器中使用链接 (https://docs.google.com/spreadsheet/ccc?key=XXXXXXXXX&output=csv) 时,一切正常。为什么我使用这个脚本总是出错:

import requests
response = requests.get("https://docs.google.com/spreadsheet/ccc?key=XXXXXXXXX&output=csv")
print(response.content)

b'Error 400 (Bad Request)!!1{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color: #222;padding:15px}body{color:#222;text-align:unset;margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px;} > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}pre{ white-space:pre-wrap;}ins{color:#777;text-decoration:none}img{border:0}@media 屏幕和 (max-width:772px){body{background:none;margin-top :0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left :-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0 %/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media 仅屏幕和 (-web kit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size :100% 100%}}#logo{display:inline-block;height:54px;width:150px}

400. 那\xe2\x80\x99 是一个错误。

服务器无法处理请求,因为它格式错误。不应重试。我们所知道的\xe2\x80\x99s。'

【问题讨论】:

    标签: python csv python-requests


    【解决方案1】:

    该链接在您的浏览器中工作正常,因为您的 gmail 帐户已在您的浏览器中登录。并非所有网站都接受来自 python 库的请求,因此您最好找到更可靠的选项并通过跟踪和错误检查兼容性,以了解它是否有效。

    点击此链接完成您的任务spread_sheet using python

    此链接提到的方法不使用谷歌 api,而只是由 pandas pandas procedure

    【讨论】:

    • 非常感谢!熊猫程序的链接有所帮助。
    • 很高兴我的回答有帮助,如果您觉得有帮助,请考虑接受并点赞
    • 是不是很有帮助
    【解决方案2】:

    您遇到的问题是您尝试访问允许用户通过浏览器访问文档的网页的 URL,即使您作为应用程序连接也是如此。这会给你带来各种各样的问题。相反,您应该尝试使用 Google Docs API here 或 Google Sheets API here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 2014-06-25
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多