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

blob.download_as_string failure (google-cloud-storage 1.3.2) #4053

Closed
ambrosejcarr opened this issue Sep 23, 2017 · 2 comments
Closed

blob.download_as_string failure (google-cloud-storage 1.3.2) #4053

ambrosejcarr opened this issue Sep 23, 2017 · 2 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API. packaging

Comments

@ambrosejcarr
Copy link

I'm having trouble using the blob.download_as_string and the related blob.download_to_file functionality of google.cloud.storage. I noticed a similar error has come up on the Google Cloud Developers slack.

I installed google-cloud more recently than any other module, so if dependencies are broken, they are not picked up by the pip3 install google-cloud invocation.

google-cloud-storage is version 1.3.2. Downgrading to version 1.2.0 fixed my problems.

  1. OS type and version: OS X 10.12.6
  2. Python version and virtual environment information: python 3.6.0
  3. google-cloud-python version:
Name: google-cloud
Version: 0.27.0
Summary: API Client library for Google Cloud
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google Cloud Platform
Author-email: googleapis-publisher@google.com
License: Apache 2.0
Location: /usr/local/lib/python3.6/site-packages
Requires: google-cloud-resource-manager, google-cloud-videointelligence, google-cloud-runtimeconfig, google-cloud-bigtable, google-cloud-datastore, google-cloud-translate, google-cloud-core, google-cloud-language, google-cloud-dns, google-cloud-error-reporting, google-cloud-pubsub, google-cloud-bigquery, google-cloud-speech, google-cloud-storage, google-cloud-monitoring, google-cloud-vision, google-cloud-spanner, google-cloud-logging
  1. Stacktrace:
> blob.download_as_string()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-46f3cd070ec1> in <module>()
----> 1 blob.download_as_string()

/usr/local/lib/python3.6/site-packages/google/cloud/storage/blob.py in download_as_string(self, client)
    500         """
    501         string_buffer = BytesIO()
--> 502         self.download_to_file(string_buffer, client=client)
    503         return string_buffer.getvalue()
    504

/usr/local/lib/python3.6/site-packages/google/cloud/storage/blob.py 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)

/usr/local/lib/python3.6/site-packages/google/cloud/storage/blob.py 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(

/usr/local/lib/python3.6/site-packages/google/resumable_media/requests/download.py in consume(self, transport)
     99
    100         if self._stream is not None:
--> 101             self._write_to_stream(result)
    102
    103         return result

/usr/local/lib/python3.6/site-packages/google/resumable_media/requests/download.py 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: __enter__
  1. Steps to reproduce:
> from google.cloud import storage
> bucket_name = a_real_bucket  # insert a real bucket here. 
> blob_name = a_real_blob  # insert a real blob here.
> client = storage.Client()
> bucket = client.bucket(bucket_name)   
> bucket.exists()
True
> blob = bucket.get_blob(blob_name)
> blob.exists()
True
> blob.download_as_string()  # produces the above error. 

@tseaver tseaver added api: storage Issues related to the Cloud Storage API. packaging labels Sep 23, 2017
@tseaver
Copy link
Contributor

tseaver commented Sep 23, 2017

Duplicate of #3747: you can work around the issue by upgrading requests, e.g.:

$ /path/to/venv/bin/pip install -U requests

@tseaver tseaver closed this as completed Sep 23, 2017
@aromeronavia
Copy link

That worked for me ^

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. packaging
Projects
None yet
Development

No branches or pull requests

3 participants