google-api-python-client: Bug in http.MediaIoBaseDownload
Problem is here. If content-range
is not found in response. This will leads to infinite loop because self._total_size
will always be None
and self._progress == self._total_size
will always results in False
hence self._done
will never be True
. Shouldn’t it raise an exception if content-range
header is not found?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 22 (2 by maintainers)
Commits related to this issue
- Handle unknown media length (#406) Some media download APIs does not support partial downloads and do not return a 'Content-length' or 'Content-range' header and is therefore never considered done.... — committed to googleapis/google-api-python-client by danielx 6 years ago
- Merge pull request #15 from orestica/get_access_token Modify the OAuth2Credentials.get_access_token() method. — committed to akrherz/google-api-python-client by craigcitro 10 years ago
This is still an issue, and a serious one because it makes it impossible to download objects from Google Cloud Storage buckets using
MediaIoBaseDownload
.Here’s another way of getting objects (this does it in one go and stores it in memory, so may not be suitable for large files):
For anyone looking for a work around:
@jonparrott ok thanks will take a look
@Capstan This code example fails as total_size is never defined, thus status is always False. This only occurs for the export_media function which does not provide a ‘size’ field. The get_media function does and has no issues.
source: [https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents]
Still Happens for
BytesIO
(and not forFilesIO
) - using theMediaIoBaseDownload
with example on https://developers.google.com/drive/api/v3/manage-downloadsadding the
fh.seek(0)
fixes itSame here. Still happening. I ended up doing
service.files().export(fileId=file_id, mimeType=mimeType).execute(http=http)
but it’s not ideal since the response is not buffered. A solution would be appreciated!For those wanting to use a
MediaIoBaseDownload
, I also did what I describe here: http://stackoverflow.com/a/41643652/72350, which basically works as always for most requests, and just gets the first chunk for those incorrect responses (theoretically it might corrupt the file). Try it at your own risk.Using google-api-python-client-1.6.4, still met the same issue, my code is like: …
… here the “total_size” is always “None” which leads “done” is always false. The target file is a 1580+ rows google spreadsheet. And it is so weird that if the file is less than 1580 rows then this issue will not happen. Hope anyone or API maintainer can help! Thanks!
Should be handled by the latest commit.