RouteTable:AWS Boto get_all_route_tables() 中的 None

RouteTable: None in AWS Boto get_all_route_tables()

当我抓取所有路线 tables 使用:

conn=boto.vpc.connect_to_region("us-east-1") c=conn.get_all_route_tables()

输出包含 RouteTable:None 的多个列表项以及路线 table 我期望的 ID:

[RouteTable:rtb-123xyzz, RouteTable:rtb-456abcc, RouteTable:None, RouteTable:None, RouteTable:None,

有人能告诉我为什么这些 none 项包含在输出中吗? 有了它们,我无法遍历以获取更多 attribute/value 信息。

谢谢,

不确定为什么某些路线 table 的 ID 是 None。可能是路由 table 创建被中止。但是遍历它们是你的问题,你可以这样做:

  • 删除那些路线 tables
  • 忽略那些路由 tables

在python中很容易忽略它们:

for rt in c:
  if rt.id  # Valid route table id
    # Do your stuff

或者只是过滤掉 None 路由 tables:

route_tables = [rt for rt in c if rt.id]