Reputation: 9702
I try to upload a zip file to my S3 bucket, but getting
AttributeError: 'ZipFile' object has no attribute 'tell' error
conn = boto.s3.connect_to_region(region_name=s3region,
aws_access_key_id=userid,
aws_secret_access_key=accesskey,
calling_format=boto.s3.connection.OrdinaryCallingFormat())
bucket = conn.get_bucket(s3bucket)
k = boto.s3.key.Key(bucket, zipf)
k.send_file(zipf) //<----Gives Exception
What is wrong here? (zipf is my zipfile)
if I modify the code like this;
with open(zipf) as f:
k.send_file(f)
I get
TypeError: coercing to Unicode: need string or buffer, ZipFile found
I created zip file like;
zipfilename = 'AAA_' + str(datetime.datetime.utcnow().replace(microsecond=0)) + '.zip'
zipf = zipfile.ZipFile(zipfilename, mode='w')
for root, dirs, files in os.walk(path):
for f in files:
zipf.write(os.path.join(root, f))
zipf.close()
Upvotes: 1
Views: 3754
Reputation: 2731
Your zipfile is created with zipf = zipfile.ZipFile(zipfilename, mode='w')
.
Following the zipfile documentation, the tell()
attribute is only defined for mode='r'
.
There is no reason to use a zipfile object, moreover in write mode, to upload a file (be it zip or whatever) that we want read, in order to upload it to S3.
Just use open(zipfilename, 'r')
before calling send_file()
on the key.
Upvotes: 2