question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'Blob' object has no attribute 'download_as_bytes'

See original GitHub issue

Problem description

Be sure your description clearly answers the following questions:

  • What are you trying to achieve? Trying to pull a file from gcp storage

  • What is the expected result? I can read a file from gcp storage

  • What are you seeing instead? Error: AttributeError: ‘Blob’ object has no attribute ‘download_as_bytes’

Steps/code to reproduce the problem

Failed on this line: for line in open(file, 'r'): I think it gets the file open and begins reading for the loop when it fails.

In order for us to be able to solve your problem, we have to be able to reproduce it on our end. Without reproducing the problem, it is unlikely that we’ll be able to help you.

Include full tracebacks, logs and datasets if necessary. Please keep the examples minimal (minimal reproducible example).

Apr 05 16:19:30 <host> docker[2234166]: File “/usr/local/lib/python3.7/site-packages/smart_open/gcs.py”, line 325, in read1 Apr 05 16:19:30 <host> docker[2234166]: return self.read(size=size) Apr 05 16:19:30 <host> docker[2234166]: File “/usr/local/lib/python3.7/site-packages/smart_open/gcs.py”, line 320, in read Apr 05 16:19:30 <host> docker[2234166]: self._fill_buffer(size) Apr 05 16:19:30 <host> docker[2234166]: File “/usr/local/lib/python3.7/site-packages/smart_open/gcs.py”, line 374, in _fill_buffer Apr 05 16:19:30 <host> docker[2234166]: bytes_read = self._current_part.fill(self._raw_reader) Apr 05 16:19:30 <host> docker[2234166]: File “/usr/local/lib/python3.7/site-packages/smart_open/bytebuffer.py”, line 152, in fill Apr 05 16:19:30 <host> docker[2234166]: new_bytes = source.read(size) Apr 05 16:19:30 <host> docker[2234166]: File “/usr/local/lib/python3.7/site-packages/smart_open/gcs.py”, line 178, in read Apr 05 16:19:30 <host> docker[2234166]: binary = self._download_blob_chunk(size) Apr 05 16:19:30 <host> docker[2234166]: File “/usr/local/lib/python3.7/site-packages/smart_open/gcs.py”, line 194, in _download_blob_chunk Apr 05 16:19:30 i<host> docker[2234166]: binary = self._blob.download_as_bytes(start=start, end=end) Apr 05 16:19:30 <host> docker[2234166]: AttributeError: ‘Blob’ object has no attribute ‘download_as_bytes’ Apr 05 16:19:30 <host> docker[2234166]: I0405 16:19:30.721222 139676694796096 gcs.py:241] close: called

Versions

Please provide the output of:

import platform, sys, smart_open
print(platform.platform())
print("Python", sys.version)
print("smart_open", smart_open.__version__)

Python 3.7.10 (default, Apr 2 2021, 22:24:51) [GCC 8.3.0] on linux Type “help”, “copyright”, “credits” or “license” for more information.

import platform, sys, smart_open print(platform.platform()) Linux-5.4.89±x86_64-with-debian-10.9 print(“Python”, sys.version) Python 3.7.10 (default, Apr 2 2021, 22:24:51) [GCC 8.3.0] print(“smart_open”, smart_open.version) smart_open 5.0.0

Tried on the latest 4 version too, same thing.

Checklist

Before you create the issue, please make sure you have:

  • Described the problem clearly
  • Provided a minimal reproducible example, including any required data
  • Provided the version numbers of the relevant software

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
geliozcommented, Jun 18, 2021

Had the same issue. Pinning to the latest version of google-cloud-storage fixed the problem.

It would be nice to pin google-cloud-storage>=1.31.0 in smart_open[gcs] dependencies, as there was no Blob.download_as_bytes method before this release: https://github.com/googleapis/python-storage/releases/tag/v1.31.0

1reaction
petedannemanncommented, Apr 6, 2021

Ok I still can’t reproduce this at all and still have no idea what your file actually is. From this log Apr 05 16:19:30 docker[2234166]: I0405 16:19:30.721222 139676694796096 gcs.py:241] close: called it looks like somehow you already closed the Blob prior to reading from it?

Can you try a minimally reproducible example like this? This is a publically available file in GCS.

path = "gs://tensorflow-nightly/prod/tensorflow/release/ubuntu_16/gpu_py37_full/nightly_release/18/20190813-010608/github/tensorflow/pip_pkg/tf_nightly_gpu-1.15.0.dev20190813-cp37-cp37m-linux_x86_64.whl"

import smart_open
import google.cloud.storage

client = google.cloud.storage.Client.create_anonymous_client()
with smart_open.open(path, transport_params=dict(client=client)) as f:
    for line in f:
        print(line)
Read more comments on GitHub >

github_iconTop Results From Across the Web

blob has not attribute open - Stack Overflow
I am trying to read file from Google cloud storage bucket with blob.open but it is giving error that blob ...
Read more >
Class Blob (2.7.0) | Python client library - Google Cloud
The component count (in case of a composed object) or None if the blob's resource has not been loaded from the server. This...
Read more >
'str' object has no attribute 'tell'" when uploading files on ...
How to solve the error "AttributeError: 'str' object has no attribute 'tell'" when uploading files on Google Cloud Storage in Python.
Read more >
I am getting failures when trying to download a blob from ...
The command failed with an unexpected error. Here is the traceback: 'BlobServiceClient' object has no attribute 'exists' Traceback (most recent call last):
Read more >
How to download files from Google Cloud Storage with Python ...
# List all objects that satisfy the filter. blobs=bucket.list_blobs(prefix=file_id, delimiter=delimiter). This will return all files from the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found