Search code examples
pythongoogle-drive-apigoogle-api-clientgoogle-api-python-client

google-api-python-client bug with media downloading


Used google-api-python-client==1.6.2

fh = io.BytesIO()
request = self.drive_service.files().export_media(
    fileId='1fwshPVKCACXgNxJtmGN94X-9RRrukiDs9q4s-n0nGlM',
    mimeType='application/vnd.openxmlformats-officedocument.wordprocessingml.document'
)
downloader = MediaIoBaseDownload(fh, request, chunksize=1024)
done = False
while done is False:
    status, done = downloader.next_chunk()
    print "Download ", status.progress(), downloader._progress, downloader._total_size, done

Output:

Download  0.0 973060 None False
Download  0.0 1946120 None False
Download  0.0 2919180 None False
Download  0.0 3892240 None False
Download  0.0 4865300 None False
Download  0.0 5838360 None False
Download  0.0 6811420 None False
Download  0.0 7784480 None False
Download  0.0 8757540 None False
...

File size of downloading file is 973060 bytes. So, the library ignores chunksize parameter and did not stop. Never stop.

So, anyone can tell me Are my requirements too high or Is the library so bad?


Solution

  • How about following sample?

    Sample :

    request = self.drive_service.files().export_media(
        fileId='1fwshPVKCACXgNxJtmGN94X-9RRrukiDs9q4s-n0nGlM',
        mimeType='application/vnd.openxmlformats-officedocument.wordprocessingml.document'
    ).execute()
    with open('sample.docx', 'wb') as f:
        f.write(request)
    

    If this doesn't work, I'm sorry.