I am a beginner with python and have been trying to learn to create twitter bots to reply to tweets from the streaming API. The following is my code. I am getting the following error when I run it:
check (): Indentation error: unindent does not match with any outer indentation level. I cannot find any indentation error
import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
import json
import time
consumer_key =
consumer_secret =
access_token =
access_secret =
def check():
datafile = file('C:\Users\User\Desktop\Handles', 'r')
found = False
for line in datafile:
if status.user.screen_name in line:
found = True
break
return found
class MyListener(StreamListener):
def on_status(self, status):
f=status.user.screen_name
if check() :
return True
else:
Append=open('Growth Handles.txt' , 'a' )
Append.write(f)
Append.close()
Reply='@handlename' + 'Check out Tomorrowland 2014 Setlist . http://.... '
api = tweepy.API(auth)
api.update_status(Reply)
time.sleep(45)
return True
def on_error(self, status):
print(status)
return True
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
twitter_stream = Stream(auth, MyListener())
twitter_stream.filter(track=['#musiclovers'])
This is how your code looks like when using notepad++:

As you can see some of your lines are indented with 4 spaces and some with tabs.
You should really use IDE when you write code, or at least use notepad++ (which is not an IDE but is good enough to understand errors like this).
I can really advise using pycharm. They have free edition and it works great.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With