Tweepy - 检查 update_status 是否成功或获取失败原因

Tweepy - Check if update_status was successful or get failure reason

我有一段代码可以发送带有 tweepy 的推文。有时由于某些不为人知的原因它无法发送推文,API 键是有效的,它最多只能每隔一到两个小时发送一条推文,并且不会重复推文。如何检查 tweepy 中的 update_status 方法是否成功完成 and/or 获取失败的原因。

当前代码为

    try:
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        api = tweepy.API(auth)
        api.update_status(tweet)
    except Exception as e:
        print("TwitterError: " + str(e))

更新: 使用 tweepy 模块提供的异常处理 tweepy.TweepError

try:
    if api.update_status(tweet):
        print("Posted")
except tweepy.error.TweepError as e:
    print(e)

Read the docs