首页 > 解决方案 > AttributeError:“NoneType”对象没有属性“create_favorite”

问题描述

我正在尝试使 twitter 自动化一点,但在 Tweepy 上的 auto like 功能上出现以下错误

Traceback (most recent call last):
File "/Users/dusandev/Desktop/TwitterBot/bot.py", line 15, in <module>
tweet.favorite()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site- 
packages/tweepy/models.py", line 375, in favorite
return self._api.create_favorite(self.id)
AttributeError: 'NoneType' object has no attribute 'create_favorite'

这是代码:

import tweepy
import time

auth = tweepy.OAuthHandler('xxxxxxxx','xxxxxx')
auth.set_access_token('xxxx-xxxx','xxxxxx')

api = tweepy.API(auth, wait_on_rate_limit=True)

search = 'solana'
number_of_tweets = 50

for tweet in tweepy.Cursor(api.search_tweets, search).items(number_of_tweets):
try:
    print('Tweet Liked')
    tweet.favorite()
    time.sleep(10)
except tweepy.TweepyException as e:
    print(e)
except StopIteration:
    break

谢谢您的帮助!

标签: pythontwittertweepy

解决方案


推荐阅读