我想要下载我的Google Drive中的文档,并向Google进行身份验证(我只希望某些用户能够访问它并且不想发布它在网上)。向Google云端硬盘进行身份验证并使用Python下载电子表格urllib2/requests
我试过使用requests
但显然我做错了什么。 在浏览器中,我可以下载我的文档到地址 https://docs.google.com/spreadsheets/d/<document key>/export?format=xls
。
所以在我的Python脚本我做到以下几点:
import os
import requests
import shutil
from requests.auth import HTTPBasicAuth
remote = "https://docs.google.com/spreadsheets/d/<document key>/export?format=xls"
username = os.environ['GOOGLEUSERNAME']
password = os.environ['GOOGLEPASSWORD']
r = requests.get(remote, auth=HTTPBasicAuth(username,password))
if r.status_code == 200:
with open("document.xls","wb") as f:
shutil.copyfileobj(r.raw, f)
但是所产生的document.xls
是空的。
我在做什么错?
感谢Marco,PyDrive似乎是一个不错的解决方案:) – lucacerone 2015-02-01 09:32:19
你有没有参考点(1)?我从未观察到这一点。 – 2015-02-05 15:29:00
这是我自己的经验,当我试图解析谷歌网站多年前。 – 2015-02-05 15:33:11