为什么状态为 'non subscriptable',我该如何解决? Python Tweepy

Why is Status 'non subscriptable' and how do I fix it? Python Tweepy

当有人用我的@handle 回复该推文时,我正在尝试使用我在下面编写的代码来获取推文中视频的媒体 url:

import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
import json

class StdOutListener(StreamListener):
    def on_data(self, data):
        clean_data = json.loads(data)
        tweetId = clean_data['id']
        tweet_name = clean_data['user']['screen_name']
auth = tweepy.OAuthHandler("consumer_key", "consumer_secret")
            auth.set_access_token("access_token", "access_token_secret")
            api = tweepy.API(auth)
            mediaupload_id = clean_data['in_reply_to_status_id']
            origtweet_media = api.get_status(mediaupload_id)
            print()
            print(origtweet_media)
            native_media = origtweet_media['extended_entities']['media'][0]['video_info']
            tweet_media = native_media['variants'][0]['url']
            print(tweet_media)

def setUpAuth():
    auth = tweepy.OAuthHandler("consumer_key", "consumer_secret")
    auth.set_access_token("access_token", "access_token_secret")
    api = tweepy.API(auth)
    return api, auth

def followStream():
    api, auth = setUpAuth()
    listener = StdOutListener()
    stream = Stream(auth, listener)
    stream.filter(track=["@YOUR_TWITTER_HANDLE"], is_async=True)

if __name__ == "__main__":
    followStream()

一切似乎都设置好了,但是当我 运行 代码时,有人回复了一条包含视频的推文(回复的人提到了我的@handle),我得到这个错误:

Exception has occurred: TypeError
'Status' object is not subscriptable
    native_media = origtweet_media['extended_entities']['media'][0]['video_info']

为什么 'Status' 不可订阅?有没有办法解决这个问题,让它成功抓取视频 url (tweet_media)?

有人请帮助我!

已解决!

仔细查看 printed origtweet_media 后,我注意到推文信息在 _json=() 中。所以我将 ._json 添加到 origtweet_media = api.get_status(mediaupload_id) 的末尾,因为它只是隔离了 json 部分,让我可以找到 tweet_media 的视频 url。新更新的行如下所示:

origtweet_media = api.get_status(mediaupload_id)._json

然后就成功了!