祝你编码器所有的新年快乐! 我在编译早期的heroku上编写Python时遇到了问题,该问题抛出了缩进错误并被此线程回答。 Python Bot indentation error, solved 无论如何,在你们的帮助下,我通过了上面提到的错误,但弹出一个奇怪的语法错误。从控制台产生Python语法错误与Tweepy
banned_accs = ['@bbc' ,'@cnn']
for tweet in tweepy.Cursor(api.search, q='#test').items():
if not any(acc == tweet.user.screen_name for acc in banned_accs):
tweet.retweet()
print('Retweeted the tweet')
# Favorite the tweet
tweet.favorite()
print('Favorited the tweet')
# Follow the user who tweeted
tweet.user.follow()
print('Followed the user')
sleep(5)
else:
pass
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break
错误是
except tweepy.TweepError as error:
^
SyntaxError: invalid syntax
有人可以帮我想出解决办法?提前致谢。
你似乎并不在你的代码中的'try'内缩进。这需要超出您期望可能抛出异常的代码部分,并且所有内容都应在该块内缩进。这是Python中的标准,与'tweepy'无关。 – roganjosh
你的尝试块在哪里启动? –
我自己犯的无意义错误。对不起,我不得不把它放在这里。谢谢你们的回复。投票删除此问题。 – AACaN