Boto3 Object put method loads 0 bytes

僤鯓⒐⒋嵵緔 提交于 2019-12-24 13:32:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!