【问题标题】:Softlayer Object Storage Python API SearchSoftlayer 对象存储 Python API 搜索
【发布时间】:2016-05-14 05:19:44
【问题描述】:

我关注softlayer-object-storage-python 是为了返回符合特定条件的我的对象列表。

无论我在搜索中输入什么内容,这段代码似乎都会返回我容器中的所有内容

sl_storage = object_storage.get_client(
    username = environment['slos_username'],
    password = environment['api_key'],
    auth_url = environment['auth_url']
)

# get container
sl_container = sl_storage[environment['object_container']]

# get list, the search function doesn't actually work...
containers = sl_container.search("icm10restapi-qa.zip.*")

我希望只取回以 icm10restapi-qa.zip 开头的内容。

我也尝试过使用^=icm10restapi-qa.zip,但也没有运气。

【问题讨论】:

    标签: api ibm-cloud-infrastructure


    【解决方案1】:

    查看方法,似乎无法按照您的意愿过滤对象:

    https://github.com/softlayer/softlayer-object-storage-python/blob/master/object_storage/client.py#L147

    API Operations for Search Services

    对于给您带来的不便,我深表歉意,我建议您尝试在您的代码中过滤这些内容。

    更新

    此脚本将帮助过滤名称以特定字符串开头的对象

    import object_storage
    import pprint
    
    # Declare username, apikey and datacenter
    USERNAME = 'set me'
    API_KEY = 'set me'
    DATACENTER = 'https://dal05.objectstorage.softlayer.net/auth/v1.0/'
    # Creating object storage connection
    sl_storage = object_storage.get_httplib2_client(USERNAME, API_KEY, auth_url=DATACENTER)
    # Declare name to filter
    name = 'icm10restapi-qa.zip'
    
    # Filtering
    containers = sl_storage.search(name)
    for container in containers['results']:
        if container.__dict__['name'].startswith(name):
            print(container)
    

    【讨论】:

    • 哦,好的,没关系。那么搜索是做什么的呢?
    • 请参阅我的回答中的“更新”部分,我附上了一个脚本,可以帮助您过滤
    • 嗨,我使用了类似的东西,但是我注意到一些奇怪的东西,我得到了重复的项目,或者有时根本没有得到这些项目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多