I am trying to transfer a .gz file with S3 using boto, and iterate over the lines in a text file without unpacking. Mysteriously, the cycle never ends; when the whole file has been read, the iteration restarts at the beginning of the file.
Let's say I create and load an input file as follows:
> echo '{"key": "value"}' > foo.json > gzip -9 foo.json > aws s3 cp foo.json.gz s3:
and I run the following Python script:
import boto import gzip connection = boto.connect_s3() bucket = connection.get_bucket('my-bucket') key = bucket.get_key('my-location/foo.json.gz') gz_file = gzip.GzipFile(fileobj=key, mode='rb') for line in gz_file: print(line)
Result:
b'{"key": "value"}\n' b'{"key": "value"}\n' b'{"key": "value"}\n' ...forever...
Why is this happening? I think that there must be something very basic that I am missing.
python amazon-s3 gzip boto
zweiterlinde
source share