I'm currently using PyDrive to automatically modify existing Google Sheets I have uploaded to my Google Drive. I then have Google Data Studio connecting to these Google Sheets so that I can then visualize them.
The only problem is that when I modify the contents of the existing Google Sheet, it then completely breaks the data connection (Data Set Configuration Error).
The ID of the file and the name stays completely the same, so I'm a bit confused as to why this happens. Any thoughts?
Here's my code for modifying existing Google Drive files:
import glob
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
all_csv = glob.glob(os.path.join(r'/file/', '*.csv'))
def upload_files():
def update_files(file_id, file_dir):
update_file = drive.CreateFile({'id': file_id})
update_file.SetContentFile(file_dir)
update_file.Upload({'convert': True})
for file_list in drive.ListFile({'q': "'*folder_ID*' in parents and trashed=false"}):
for file1 in file_list:
for x in all_csv:
if file1['title'] == x.split('\\')[-1].split('.')[0]:
update_files(file1['id'], x)
upload_files()