嗨,我是Python的新手,我只是一个学习者,最近我尝试将两个脚本(转发和推文)组合为一个,两个脚本之间有一个间隔,但不幸的是,它总是以错误结尾,我不知道不知道如何解决这个错误。
这是我的代码:
# importing the module
import tweepy
from time import sleep
import random
# personal information
api_key = "xxxx"
api_secret_key = "yyyy"
access_token = "xxxx"
access_token_secret ="yyyy"
# authentication
auth = tweepy.OAuthHandler(api_key, api_secret_key)
auth.set_access_token(access_token, access_token_secret)
# authentication of access token and secret
api = tweepy.API(auth)
#put your tweets here
#some of these tweets have been taken from the top section of the hashtag #BoycottPexa,credit goes to the respective users
list=["t.co/DVIh9Pqtu",
"t.co/mkPzaqXge",
"t.co/ql9UxICTy",
"t.co/dDSkDij92",
"t.co/LeTY4JRQP"
]
# Retweet and Favorite the tweet
for tweet in tweepy.Cursor(api.search, q = ("#twitter -filter:retweets"),lang="en").items():
try:
print("\nTweet by: @" + tweet.user.screen_name)
tweet.retweet()
print("Retweeted the tweet")
tweet.favorite()
print("Favorited the tweet")
sleep(360)
# Posting of tweets
for i in range(len(list)):
try:
#insert more hashtags if you want to here
string = f"{random.randint(0,99)}"
api.update_status(status =string+" "+" #Twitter"+" "+ list[i])
print("successfully tweeted")
sleep(360)
except KeyboardInterrupt:
exit()
我收到的错误:
File "post.py", line 95
2020-07-26T07:45:45.598784+00:00 app[worker.1]: tweet.favorite()
2020-07-26T07:45:45.598785+00:00 app[worker.1]: ^
2020-07-26T07:45:45.598786+00:00 app[worker.1]: IndentationError: unexpected indent
任何帮助将不胜感激,并在此先感谢。
答案 0 :(得分:0)
如上述用户所述,可能会出错,但我看到tweet.favourite之类的缩进错误。
答案 1 :(得分:0)
正如错误所言:代码中存在缩进问题。
似乎在这里发生:
tweet.retweet()
print("Retweeted the tweet")
# This bit has no reason to be indented
tweet.favorite()
print("Favorited the tweet")
sleep(360)