python boto'NoneType'对象没有属性'stop_isntances'。

问题描述 投票:0回答:1

我正在学习python boto模块,我试图停止一个运行的实例。

import boto.ec2
conn = boto.ec2.connect_to_region("us-west-2")
conn.stop_instances(instance_ids=['i-0aa5ce441ef7e0e2a'])

但我得到的错误,说。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'stop_instances'

我给AWS_access keys for boto。

谁能帮我解决这个错误?

python python-2.7 python-3.x boto boto3
1个回答
0
投票

正如 @kindall 指出的,你的 conn 对象没有被初始化(它是NoneType)。我也看到你在例子中使用了boto,但我想我可以提供一个使用boto3的例子。

import boto3

boto3_session = boto3.Session(profile=some_profile_you_configured)
boto3_client = boto3_session.client('ec2', region_name='us-west-2')

response = boto3_client.stop_instances(InstanceIds=['i-0aa5ce441ef7e0e2a'])

© www.soinside.com 2019 - 2024. All rights reserved.