【问题标题】:python list_objects() only accepts keyword argumentspython list_objects() 只接受关键字参数
【发布时间】:2021-10-10 18:16:02
【问题描述】:

我创建了以下循环,它获取证书CERTIFICATION_PATH 的路径。由路径组成:bucket/organisation/uuid

import json
import boto3

for data in json_data:
    MQTT_TOPIC = "{organisation}/{device_vendor}/{device_type}".format(**data)
    CERTIFICATION_PATH = "{}/{organisation}/{uuid}".format(bucket, **data)
    
for uuid_index, uuid in enumerate(uuid_list): 
    result = client.list_objects(CERTIFICATION_PATH)
    print('-------------------')
    print(result)
    print('-------------------')

当我执行上述操作时,我收到了错误 list_objects() only accepts keyword arguments.。是否有另一种方法可以列出CERITIFCATION_PATH中的对象

【问题讨论】:

    标签: python python-3.x boto3


    【解决方案1】:

    不仅仅是传入一个字符串(在您的情况下为CERTIFICATION_PATH),还需要将bucketprefix 分别传入list_objects()

    你还需要使用关键字参数,也就是说,你必须以key=value的形式传入参数。

    以下或类似的应该:

    client.list_objects(
        Bucket=bucket,
        Prefix=f"{organisation}/{uuid}",
    )
    

    bucketorganisationuuid 需要在某处定义。

    【讨论】:

    • 我试过了,很遗憾得到了错误Missing required parameter in input: "Bucket" Unknown parameter in input: "bucket", must be one of: Bucket, Delimiter, EncodingType, Marker, MaxKeys, Prefix, RequestPayer, ExpectedBucketOwner Unknown parameter in input: "prefix", must be one of: Bucket, Delimiter, EncodingType, Marker, MaxKeys, Prefix, RequestPayer, ExpectedBucketOwner
    • 抱歉,必须是 BucketPrefix 而不是 bucketprefix。我更新了答案。
    猜你喜欢
    • 1970-01-01
    • 2021-09-24
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    相关资源
    最近更新 更多