首页 > 解决方案 > 尝试从 Status 对象返回字段值时出错

问题描述

我有以下代码:

tweet = random.choice(result)
pprint(tweet)
tweet_id = tweet['id']

第一行正在工作,因为 pprint(tweet) 正在打印:

Status(ID=1228151646292762624, ScreenName=None, Created=Fri Feb 14 02:59:05 +0000 2020, Text='one person followed me // automatically checked by [REDACTED])

到控制台。问题出在 tweet_id = tweet['id'] 中。它给了我错误:

Task hello.tasks.my_task[13181b70-70a0-44cc-94d7-87f173fbe3cb] raised unexpected: TypeError("'Status' object is not subscriptable",)

显然状态对象的功能不像字典。那么如何从中获取字段“ID”呢?

标签: pythontwitter

解决方案


推荐阅读