Tweepy user_timeline 占据 1 个位置,但有 2 个位置出错

Tweepy user_timeline takes 1 position but 2 were given error

我正在制作一个机器人,它使用 user_timeline 打印来自特定用户的推文,但是当我 运行 它时它给了我这个错误。

TypeError: user_timeline() takes 1 positional argument but 2 were given

这是我的完整代码;显然我删除了密钥和令牌

# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# screen name of the account to be fetched
screen_name = "geeksforgeeks"
  
# fetching the statuses
statuses = api.user_timeline(screen_name)
  
print(str(len(statuses)) + " number of statuses have been fetched.")

根据 source-code,您必须在方法 API.user_timeline 中使用关键字参数。

因此更改此行:

statuses = api.user_timeline(screen_name)

进入:

statuses = api.user_timeline(screen_name=screen_name)

Tweepy v4.0.0 changed API.user_timeline 不接受任何位置参数。
错误中引用的 1 个位置参数是 self.
您可以将 screen_name 作为 screen_name 关键字参数传递。