Reputation: 13
i'm attempting to run a twitter bot written in python that i found on github but i am getting errors.
this is the error
Traceback (most recent call last):
File "twitterbot_retweet.py", line 15, in <module>
for tweet in tweepy.Cursor(api.search, q=QUERY).items():
AttributeError: 'API' object has no attribute 'search'
i have no idea what it means but the following is the code i am currently working with
import tweepy
from time import sleep
from credentials import *
from config import QUERY, FOLLOW, LIKE, SLEEP_TIME
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
print("Twitter bot which retweets,like tweets and follow users")
print("Bot Settings")
print("Like Tweets :", LIKE)
print("Follow users :", FOLLOW)
for tweet in tweepy.Cursor(api.search, q=QUERY).items():
try:
print('\nTweet by: @' + tweet.user.screen_name)
tweet.retweet()
print('Retweeted the tweet')
# Favorite the tweet
if LIKE:
tweet.favorite()
print('Favorited the tweet')
# Follow the user who tweeted
#check that bot is not already following the user
if FOLLOW:
if not tweet.user.following:
tweet.user.follow()
print('Followed the user')
sleep(SLEEP_TIME)
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break
thanks in advance. i've never worked on anything in python this technical before but i'm a quick learner. this is where i got the code at... https://github.com/gauravssnl/Python-Twitter-Bot
(cont.)
so i changed
for tweet in tweepy.Cursor(api.search, q=QUERY).items():
to
for tweet in tweepy.Cursor(api.search_tweets, q=QUERY).items():
and now this is the error i am receiving...
Traceback (most recent call last):
File "twitter-bot-0.py", line 20, in <module>
tweet.retweet()
File "/home/deusopus/.local/lib/python3.8/site-packages/tweepy/models.py", line 369, in retweet
return self._api.retweet(self.id)
AttributeError: 'NoneType' object has no attribute 'retweet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "twitter-bot-0.py", line 37, in <module>
except tweepy.TweepError as e:
AttributeError: module 'tweepy' has no attribute 'TweepError'
i have no idea what it means and the API documentation presents commands but as they are out of context, i struggle to grasp how they are implemented. like i said though, i am a quick learner and i appreciate any and all assistance. i'm just trying to have fun.
Upvotes: 0
Views: 397
Reputation: 736
search
is not a valid attribute in tweepy. The correct attribute is search_tweets
:
for tweet in tweepy.Cursor(api.search_tweets, q=QUERY).items():
Upvotes: 1