Q:

How can I download files from team drives?

I'd like to periodically download and upload a file from a shared teams drive on google drive. I can upload to the folder, but not download.
This is what I've tried
team_drive_id = 'YYY'
file_to_download= 'ZZZ'
parent_folder_id = 'XXX'

f = drive.CreateFile({
        'id':file_to_download,
        'parents': [{
        'kind': 'drive#fileLink',
        'teamDriveId': team_folder_id,
        'id': parent_drive_id
    }]
})
f= drive.CreateFile({'id': file_to_download})
f.GetContentFile('test.csv', mimetype='text/csv')

But this is what I get:
ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/file_to_download?alt=json returned "File not found: file_to_download">

Any suggestions?

A:

Following the documentation that can be seen here
First you create the file:
f = drive.CreateFile({'id': file_to_download})

then you set the content on the file
f.SetContentString("whatever comes inside this file, it is a csv so you know what to expect to be here")

and to finish the upload you need to do
f.Upload()

after that, the file is properly created there, you can read it using the GetContentString method

