I want to download a document from my Google Drive that verifies my Google account (I only want certain users to be able to access it and do not want to publish it on the web). I've tried using requests, but it seems like I'm doing something incorrectly. By navigating to the URL https://docs.google.com/spreadsheets/d/document key>/export?format=xls in a browser, I may download my document.
So in my python script :
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:
However, the resulting document.xls is empty.
What am I doing wrong?