Reputation: 1756
I have watched the following video where a demo is given about accessing google sheets without authentication:-
https://youtu.be/t6WSY9D_ORQ?list=LL
As per the video I am unable to access my google sheet in pandas with the following code:-
import pandas as pd
sheet_id = "my_sheet_id"
r = "https://docs.google.com/spreadsheets/d/{}/export?format=csv".format(sheet_id)
df = pd.read_csv(r)
df.head()
The exception I get is:-
HTTP Error 400: Bad Request
This same code works for the following google sheet which is public:-
https://docs.google.com/spreadsheets/d/1x9p3nqTf9fBx8I4lb3WMC_K0BLaIU8Z-7kj7MVani3U/edit?usp=sharing
where the sheet_id = "1x9p3nqTf9fBx8I4lb3WMC_K0BLaIU8Z-7kj7MVani3U"
Do I need to add some headers/parameters for this to work?
Upvotes: 1
Views: 2510
Reputation: 201473
How about modifying the endpoint as follows? This endpoint can be seen at exportLinks
of the method of "Files: get" in Drive API. Ref
r = "https://docs.google.com/spreadsheets/d/{}/export?format=csv".format(sheet_id)
r = "https://docs.google.com/spreadsheets/export?id={}&exportFormat=csv".format(sheet_id)
Upvotes: 1