问题
The following loads an empty file to my s3 bucket. Why?
df = pd.DataFrame([[1,2,3],[324,34,25], [463,23,43]])
out = df.to_csv(index=False) # unicode string (i'm in python 3)
s3 = boto3.resource('s3')
BUCKET = "MyBucketThatDefExistsAndIHaveAccessTo"
bucket = s3.Bucket(BUCKET)
obj = bucket.Object('TEST1')
obj.put(df.to_csv(index=False)) # loads an empty file "TEST1" to my bucket.
# I've also tried, but same result.
obj.put(bytes(df.to_csv(index=False), 'utf8'))
回答1:
Should it not be,
obj.put(Body=df.to_csv(index=False)) # loads an empty file "TEST1" to my bucket.
Missing Body named parameter. Since first parameter is ACL, you need to specify the name.
Hope it helps.
回答2:
I'm just dumb. Needs the Body=
kwarg.
obj.put(Body=df.to_csv(index=False)
works
来源:https://stackoverflow.com/questions/49279640/boto3-object-put-method-loads-0-bytes