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.

Boto3 S3 StreamingBody().read() reads once and returns nothing after that

See original GitHub issue
>>> a = client.get_object(Bucket='imgtest',Key='testimage1.jpg')
>>> a['Body'].read()
b'...\xadk\xc9,\xda\xe7\xcb\xb7$\x91\xf7\xb3\xd3>\xd5V...'
>>> a['Body'].read()
b''

complete bytes removed for brevity. I get an object, and read it. Then I read it again, but no bytes are returned.

If this stream acts as a normal file IO stream, how can I seek to the beginning of the stream? seek() does not seem to be a method on the streamingBody object.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
danielmorozoffcommented, Aug 20, 2017

Is there a reason why the StreamingBody, is not seekable? This becomes quite problematic when attempting to download portions of large files asynchronously. And what is the recommended way to do this?

7reactions
ghostcommented, Mar 9, 2022

If someone is having the problem 'bytes' object has no attribute 'seek' I solved with the following:

  obj = s3.get_object(Bucket='Mybucket', Key='MyObjKey')
  body = obj['Body']
  file_like_obj = io.BytesIO(body.read())
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to read botocore.response.StreamingBody due to ...
The object is returned as botocore.response.Streamingbody . Usually it can be read using strmingbody.read() method. But when I try to use read, ...
Read more >
Response Reference — botocore 1.29.34 documentation - AWS
Return an iterator to yield lines from the raw stream. This is achieved by reading chunk of bytes (of size chunk_size) at a...
Read more >
Streaming S3 objects in Python | blog
First, I set up an S3 client and looked up an object. import boto3 s3 = boto3.client('s3', aws_access_key_id='mykey', aws_secret_access_key=' ...
Read more >
How to read a file from S3 with the Python SDK - YouTube
In this video I will show you how to get and read a text file from Amazon S3 using Boto3, the Python SDK...
Read more >
How to read CSV file from Amazon S3 in Python
import codecs import csv import boto3 client = boto3.client("s3") def ... interested in is the return value of the get_object() method call.
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