祝你編碼器所有的新年快樂! 我在編譯早期的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