- Home
- Python
- Authenticate To Google Drive And Download Spreadsheet With Python Urllib2requests
Authenticate to Google Drive and download spreadsheet with Python urllib2/requests
Tags: python , http , download , excel , python-requests Answers: | Viewed 2,024 times
I would like to download a document I have in my Google Drive authenticating to Google (I only want certain users to be able to access it and do not want to publish it on the web).
I have tried using requests but apparently I am doing something
wrong.
From a browser I can download my document going to the address
//docs.google.com/spreadsheets/d/<document key>/export?format=xls.
So in my python script I do the following:
import os
import requests
import shutil
from requests.auth import HTTPBasicAuth
remote = "//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)
however the resulting document.xls is empty.
What am I doing wrong?
Some Code Answers
import os import requests import shutil from requests.auth import HTTPBasicAuth remote = "//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)
wget -O data.csv "//docs.google.com/spreadsheets/d/***SHARED-SECRET***/export?format=csv"
import urllib2 from cookielib import CookieJar spreadsheet_url = "//docs.google.com/spreadsheets/d/***SHARED-SECRET***/export?format=csv" opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(CookieJar())) response = opener.open(spreadsheet_url) with open("data.csv", "wb") as f:
f.write(response.read())
More Answers Related Authenticate To Google Drive And Download Spreadsheet With Python Urllib2requests
Authenticate to Google Drive and download spreadsheet …
1 week ago Use the official google-drive API. Also, the Python client library has a nice tutorial and this page describes how to download files from google-drive. If you want to write even less code, then …
Show details
› See also: File
Download a spreadsheet from Google Drive / Workspace …
3 days ago pip install gsheets. Log in to the Google Developers Console with the Google account whose spreadsheets you want to access. Create (or select) a project and enable the Drive API and …
› Reviews: 2
Show details
Upload and Download files from Google Drive storage …
1 week ago Nov 25, 2020 · To Upload a File, we will use the FileUpload function. We only need the file path to upload a file. From the file path, we can easily extract the file name and find its mime-type …
› Estimated Reading Time: 4 mins
Show details
› See also: Function File
How to Connect Python to Google Sheets | Coupler.io Blog
1 week ago Apr 07, 2021 · Click on “ Enable API and Services ”. Search for Google Drive API and click on “ Enable ”. Do the same for the Google Sheets API. Click on “ Create Credentials ”. Select “ …
Show details
Python 3 Google Spreadsheet or Sheets API Example to Download …
1 week ago Sep 20, 2021 · Build Google Drive API File Direct Download Link Generator Tool in Browser Using HTML5 & Javascript Full Project For Beginners ; Google Apps Script to Download …
Show details
How to authenticate Python to access Google Sheets with Service …
1 week ago Oct 28, 2021 · Create JSON file with credentials. After creating the Service Account you will see a view with your credentials. Please click on your Service Account. You will see its details. …
Show details
› See also: File
How to Use Google Drive API in Python - Python Code
6 days ago First, you need to have a Google account with Google Drive enabled. Head to this page and click the "Enable the Drive API" button as shown below: A new window will pop up; choose …
Show details
Google Spreadsheets Python download | SourceForge.net
3 days ago Aug 31, 2022 · Reviews. gspread is a Python API for Google Sheets. A service account is a special type of Google account intended to represent a non-human user that needs to …
Show details
› See also: .net
Set up authentication to Python package repositories
4 days ago Sep 14, 2022 · You must authenticate to Artifact Registry when you use a third-party application to connect to a repository. You do not need to configure authentication for Cloud Build or …
Show details
Google Sheets API Python: Authenticate Google Sheet …
2 days ago Oct 14, 2020 · To see the full, Introduction to Python course from Simon Sez IT. Go here: //www.simonsezit.com/courses/web-development/introduction-to-python-training...
› Author: Simon Sez IT
› Views: 5.6K
Show details
› See also: Python
Master Google Sheets API in Python (cheat sheet) - Medium
3 days ago Mar 03, 2021 · Download the key, you are done. That’s the shortest “Create a service account” section I’ve ever seen. If it was too short, check this article. Package installation & import. To …
Show details
Authenticate User To Access A Drive Spreadsheet Colab
1 week ago Aug 21, 2021 · This spreadsheet google colab has access. One can always ready to get the image to read and data import at real python can add your drive to authenticate access a …
Show details
› See also: Python Image
Google Drive API in Python | Getting Started - YouTube
4 days ago Google Drive API allows you to create apps that leverage Google Drive cloud storage. You can develop applications that integrate with Google Drive, and creat...
Show details