运行以下代码时,出现错误:AttributeError: 'Status' object has no attribute 'retweeted_status'
for tweet in Cursor(api.user_timeline, screen_name=user_name,count=200).items(3200):
is_tweet_reply = True if tweet.in_reply_to_screen_name != "" else False
is_tweet_retweet = True if tweet.text[0:3] == "RT " else False
if is_tweet_retweet == True:
original_tweeter_name = tweet.retweeted_status.user.screen_name
original_tweeter_id = tweet.retweeted_status.user.id
original_tweet_id = tweet.retweeted_status.id
else:
original_tweeter = None
original_tweeter_id = None
original_tweet_id = None
感谢所有可能的解决方案。
答案 0 :(得分:1)
您可以尝试使用try except
块来获取转发的推文。
for tweet in Cursor(api.user_timeline, screen_name=user_name,count=200).items(3200):
is_tweet_reply = True if tweet.in_reply_to_screen_name != "" else False
try:
original_tweeter_name = tweet.retweeted_status.user.screen_name
original_tweeter_id = tweet.retweeted_status.user.id
original_tweet_id = tweet.retweeted_status.id
except AttributeError:
original_tweeter = None
original_tweeter_id = None
original_tweet_id = None