简体   繁体   English

如何将boto3过滤器用于布尔值

[英]how to use boto3 Filters for boolean value

I'm using boto 3 in python 3.5.2 trying to describe ec2 images. 我在python 3.5.2中使用boto 3试图描述ec2图像。 The doc says one of the available filters is 'is-public': 医生说可用的过滤器之一是“公开”的:

is-public - A Boolean that indicates whether the image is public.

But the Filter syntax wants a list of strings - and only a list of strings - for the Value. 但是Filter语法只需要一个字符串列表-仅一个字符串列表作为Value。 If I try passing a Boolean, it gives me a type error: 如果我尝试传递布尔值,则会给我一个类型错误:

Invalid type for parameter Filters[0].Values[0], value: False, type: <class 'bool'>, valid types: <class 'str'>

My code: 我的代码:

  response = session.client("ec2").describe_images(
Filters=[
  {'Name': 'is-public',
   'Values': [False],
  },

How do I pass a Boolean filter when it will only accept a string? 当它仅接受字符串时,如何传递布尔过滤器?

Thanks... Bill 谢谢...比尔

This works for me... use lower case. 这对我有用...使用小写。

    ami_filter = [{"Name": "platform", 'Values': ["windows"]}, 
        {"Name": "virtualization-type", 'Values': ["hvm"]}, 
        {"Name": "image-type", 'Values': ["machine"]},
        {"Name": "architecture", 'Values': ["x86_64"]},
        {"Name": "state", 'Values': ["available"]},
        {"Name": "is-public", 'Values': ['false']}]

    ami_owners = ['amazon']
    results = client.describe_images(Filters=ami_filter, Owners=ami_owners)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM