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

时间:2017-10-10 05:19:22

标签: python python-2.7 twitter tweepy

我有一段代码应该发送带有tweepy的推文。有时,由于某些未知的原因,它无法发送推文,API密钥有效,它只能每小时或每两小时发送一条推文,而且推文不会重复。如何检查来自tweepy的update_status方法是否成功完成和/或获取失败的原因。

目前的代码是

    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))

1 个答案:

答案 0 :(得分:1)

<强>更新 使用tweepy模块tweepy.TweepError

提供的异常处理
try:
    if api.update_status(tweet):
        print("Posted")
except tweepy.error.TweepError as e:
    print(e)

Read the docs