我有一段代码应该发送带有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))
答案 0 :(得分:1)
<强>更新强>
使用tweepy模块tweepy.TweepError
try:
if api.update_status(tweet):
print("Posted")
except tweepy.error.TweepError as e:
print(e)