iterative / PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.
https://docs.iterative.ai/PyDrive2
Other
585 stars 69 forks source link

Getting a googleapiclient.http warning despite file being downloaded #143

Open aeltanawy opened 3 years ago

aeltanawy commented 3 years ago

I'm using PyDrive2 v.1.10.0 on Mac to download google doc as docx but I keep getting the following warning even though the file gets downloaded anyway:

WARNING:googleapiclient.http:Encountered 403 Forbidden with reason "fileNotDownloadable"

Any idea how to silence that or prevent it from happening? Can someone explain why I am getting this warning?

Here is my code:

drive_files = drive.ListFile({'q': f"'{drive_id}' in parents and trashed=false"}).GetList()
for file in drive_files:
    file.GetContentFile(file_path, mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document')

Note: I get the same warning with mimetype="application/pdf" but not with mimetype="application/zip"

Thanks in advance!

shcheklein commented 3 years ago

What happens if you don't specify its mimetype?

aeltanawy commented 3 years ago

What happens if you don't specify its mimetype?

@shcheklein I still get the same warning. Also, without a mimetype, the downloaded document is not recognizable as a docx file.

supermitch commented 8 months ago

I can explain why this is happening. Check the code here: https://github.com/iterative/PyDrive2/blob/main/pydrive2/files.py#L336-L363

PyDrive2 is doing a try/except. It first tries to download the file, but if the file is a Google online-only format, the Drive API throws a "403 FileNotDownloadable". When that happens, PyDrive2 resorts to the "export file" method, and converts the drive file format as required, e.g. Google spreadsheets are downloaded as Excel files.

So either requests or googleapiclient code is logging the warning, not PyDrive2. Stay tuned; I am just in the process of figuring out how to mute these specific errors.