Google drive and colab integration - How to download using file ID from Drive?

Hello Everyone,
There is a problem while downloading file from google drive into google colaboratory.

# Download a file based on its file ID.
# A file ID looks like: laggVyWshwcyP6kEI-y_W3P8D26sz
downloaded = drive.CreateFile({'id': file_id})
print('Downloaded content "{}"'.format(downloaded.GetContentString()))

When I found link for file id from goggle drive as shown in the video:
Id is not shown here in link.
I am working with downloaded file “mobile_cleaned.csv” from padhai platform and uploaded it on drive. I didn’t created the file.

When I try another way of finding file ID as :

# List .csv files in the root.
# Search query reference:
listed = drive.ListFile({'q': "title contains '.csv' and 'root' in parents"}).GetList()
for file in listed:
  print('title {}, id {}'.format(file['title'], file['id']))

I get the following error.

InvalidConfigError: Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)

Hi @Mugdha,
I’m not able to get your problem, are you trying to import a file from google drive to your colab, or save a file from colab to drive?

I am trying to import the file from google drive to google colab.
My problem is I am not able to find the file id using both the ways (listing and downloading).

Have you tried that drive integration code snippet ?

(if your in hurry )You can directly download and upload it in colab files. Then use the correct path of the file while reading .csv

I tried following 2 code snippets as shown in the video:
Listing files in Google Drive and Downloading files or importing data from google drive

I too faced the similar issue. The id now is between / and / i.e ‘1QYZVSFH-4ARRxKmm95jqAIbW_UhdGToW’ in your case. Hope it helps

1 Like

Did you edited anything in the file named “mobile_cleaned.csv”?
Because now everything is ok. I am able to get file id by listing and download file from google drive into google colaboratory.

No, I didn’t edit the mobile_cleaned.csv file.

Ok… but its working now.
Problem has been solved.
Thank you all who helped me.