【发布时间】:2021-12-09 17:08:09
【问题描述】:
我正在制作一个使用 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只接受关键字参数:def user_timeline(self, **kwargs): -
函数调用
api.user_timeline(screen_name)出现错误,因为该方法不期望screen_name作为参数。别管它。