改变一个对象元数据botocore [英] Changing an objects metadata with botocore

查看:331
本文介绍了改变一个对象元数据botocore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用botocore因为我使用python 3,不能用博托。于是我跟着这里的例子,并可以上传文件

 进口botocore.session

会议= botocore.session.get_session()
S3 = session.get_service(S3)
操作= s3.get_operation('PutObject)
终点= s3.get_endpoint(美东-1')
计划生育=打开('my_large_local_file,RB)
水库,res_data = operation.call(端点,桶='我斗,关键='/我的/键,身体= FP,ACL ='公读)
 

不过,我不知道如何设置的元数据,它是不可能随时随地记录。在随机我试着只是增加元数据kwarg

 ,元数据= {键:值}
 

但随后抛出此错误

 文件/usr/local/lib/python3.2/dist-packages/botocore/auth.py,线路382,与< genexpr>
custom_headers [LK] =''。加入(v.strip()的V IN
AttributeError的:'快译通'对象有没有属性'带'
 

但是,当我试图改变从字典类型,这样,说,像

字符串

 元={键:值}
 

然后我得到一个不同的错误,主要理由是预计的字典

 文件/usr/local/lib/python3.2/dist-packages/botocore/parameters.py,线路408,在验证
TYPE_NAME ='地图',参数=个体经营)
botocore.exceptions.ValidationError:无效值(键:值)参数图:类型的映射元数据
 

解决方案

由于garnaat指出,正如我后来发现签入botocore GitHub的问题列表(和AWS-CLI github上),这是一个尚未解决的问题,所以我会考虑这个回答

I'm using botocore because I'm using python 3 and can't use boto. So I followed the example here and can upload a file

import botocore.session

session = botocore.session.get_session()
s3 = session.get_service('s3')
operation = s3.get_operation('PutObject')
endpoint = s3.get_endpoint('us-east-1')
fp = open('my_large_local_file', 'rb')
res, res_data = operation.call(endpoint, bucket='my-bucket',key='/my/key', body=fp, acl='public-read')

But I have no idea how to set the metadata and it isn't documented ANYWHERE. At random I tried just adding a metadata kwarg

, metadata={key:value} 

but then it threw this error

File "/usr/local/lib/python3.2/dist-packages/botocore/auth.py", line 382, in <genexpr>
custom_headers[lk] = ','.join(v.strip() for v in
AttributeError: 'dict' object has no attribute 'strip'

But when I try to change the type from a dict so, say, a string like

metadata="{key:value}"

I then get a different error, basically saying it expects a dict

File "/usr/local/lib/python3.2/dist-packages/botocore/parameters.py", line 408, in validate
type_name='map', param=self)
botocore.exceptions.ValidationError: Invalid value (key:value) for param map:Metadata of type map

解决方案

As garnaat stated, and as I later found out checking the issue list in the botocore github (and the aws-cli github) this is an unresolved issue so I'll consider this answered

这篇关于改变一个对象元数据botocore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆