使用 Tweepy:类型错误:get_user() 需要 1 个位置参数,但给出了 2 个

问题描述 投票:0回答:1
api = tweepy.API(auth) 

# using get_user with id
_id = "103770785"
user = api.get_user(_id)

# printing the name of the user
print("The id " + _id + " corresponds to the user with the name : " + user.name)

这是我的代码。我找不到此消息的解决方案:

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

python tweepy
1个回答
0
投票

API.get_user
不接受任何位置参数。
错误中提到的是
self

您需要将
_id
作为
user_id
kwarg 进行传递。
请参阅 Tweepy 文档中的相关常见问题解答部分

api = tweepy.API(auth) 

# using get_user with id
_id = "103770785"
user = api.get_user(user_id=_id)

# printing the name of the user
print("The id " + _id + " corresponds to the user with the name : " + user.name)
© www.soinside.com 2019 - 2024. All rights reserved.