我是python的初学者,并且一直在努力学习创建twitter机器人来回复来自流API的推文。以下是我的代码。运行时出现以下错误:
check(): 缩进错误:unindent与任何外部缩进级别不匹配。 我找不到任何缩进错误
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'])