Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__exit__ without further info when downloading gzipped file #3939

Closed
deepdad opened this issue Sep 9, 2017 · 4 comments
Closed

__exit__ without further info when downloading gzipped file #3939

deepdad opened this issue Sep 9, 2017 · 4 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API.

Comments

@deepdad
Copy link

deepdad commented Sep 9, 2017

def download_blob(bucket_name, source_blob_name, destination_file_name):
#Downloads a blob from the bucket.
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
print(bucket.exists(client=storage_client))
print(bucket.get_blob(blob_name=source_blob_name))
with open(destination_file_name, 'wb') as file_obj:
blob.download_to_file(file_obj=file_obj)
#blob.download_to_filename(destination_file_name)

print('Blob {} downloaded to {}.'.format(
    source_blob_name,
    destination_file_name))

download_blob('test-ml-storage', 'deepdad/sample.tar.gz', './sample.tar.gz')

AttributeErrorTraceback (most recent call last)
in ()
20 destination_file_name))
21
---> 22 download_blob('test-ml-storage', 'deepdad/sample.tar.gz', './sample.tar.gz')

in download_blob(bucket_name, source_blob_name, destination_file_name)
13 print(bucket.get_blob(blob_name=source_blob_name))
14 with open(destination_file_name, 'wb') as file_obj:
---> 15 blob.download_to_file(file_obj=file_obj)
16 #blob.download_to_filename(destination_file_name)
17

/opt/conda/envs/py27/lib/python2.7/site-packages/google/cloud/storage/blob.pyc in download_to_file(self, file_obj, client)
462
463 try:
--> 464 self._do_download(transport, file_obj, download_url, headers)
465 except resumable_media.InvalidResponse as exc:
466 _raise_from_invalid_response(exc)

/opt/conda/envs/py27/lib/python2.7/site-packages/google/cloud/storage/blob.pyc in _do_download(self, transport, file_obj, download_url, headers)
416 if self.chunk_size is None:
417 download = Download(download_url, stream=file_obj, headers=headers)
--> 418 download.consume(transport)
419 else:
420 download = ChunkedDownload(

/opt/conda/envs/py27/lib/python2.7/site-packages/google/resumable_media/requests/download.pyc in consume(self, transport)
99
100 if self._stream is not None:
--> 101 self._write_to_stream(result)
102
103 return result

/opt/conda/envs/py27/lib/python2.7/site-packages/google/resumable_media/requests/download.pyc in _write_to_stream(self, response)
60 response (~requests.Response): The HTTP response object.
61 """
---> 62 with response:
63 body_iter = response.iter_content(
64 chunk_size=_SINGLE_GET_CHUNK_SIZE, decode_unicode=False)

AttributeError: exit

@dhermes dhermes self-assigned this Sep 9, 2017
@dhermes dhermes added the api: storage Issues related to the Cloud Storage API. label Sep 9, 2017
@dhermes
Copy link
Contributor

dhermes commented Sep 9, 2017

@deepdad Sorry this issue occurred for you. See #3841 for an explanation of why it's happening.

Simply upgrade to requests >= 0.18.0 and the error will be resolved.

@dhermes dhermes closed this as completed Sep 9, 2017
@deepdad
Copy link
Author

deepdad commented Sep 10, 2017

#3841 has no explanation and requests is up to date

​import requests
print (requests.version)

2.14.2

@deepdad deepdad changed the title __exit__ without further info when doanloading gzipped file __exit__ without further info when downloading gzipped file Sep 10, 2017
@dhermes
Copy link
Contributor

dhermes commented Sep 10, 2017

Sorry, I mistyped, the minimum version is 2.18.0, not 0.18.0. "Up-to-date" would be the latest version on PyPI right now (2.18.4).

Sorry for the lack of information in #3841, I had to click my way through to find the real issue (#3736).

The issue is caused by using a requests.Response object as a context manager.

@deepdad
Copy link
Author

deepdad commented Sep 10, 2017

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

No branches or pull requests

2 participants