我正在尝试使用boto3列出sns主题
我正在使用此代码
import boto3
import pprint
response = client.list_topics(
NextToken='string'
)
list_topics=[]
for each_reg in response['topic']:
print(each_reg['topic])
但我收到此错误
File "kri.py", line 14
print(each_reg['topic])
^
SyntaxError: EOL while scanning string literal
它应该是:
list_topics=[]
for each_reg in response['topic']:
print(each_reg['topic'])
并且你也需要导入sns
。
client = boto3.client('sns', region_name='us-east-1') # add your region_name here
更新:
import boto3
client = boto3.client('sns', region_name='us-east-1')
response = client.list_topics()
for each_reg in response['Topics']:
print(each_reg['TopicArn'])
我使用了您的代码bro,但收到此错误botocore.errorfactory.InvalidParameterException:调用ListTopics操作时发生了错误(InvalidParameter):无效的参数:NextToken
这是我的代码兄弟
import boto3 import pprint client = boto3.client('sns') response = client.list_topics( NextToken='list_topics' ) list_topics=[] for each_reg in response['topic']: print(each_reg['topic'])
这是因为,您需要指定区域,我已经更新了代码段。请检查并让我知道一次。
同样的错误即将到来。
谢谢你,兄弟。