我正在尝试使用 Twython 在 python 中使用 Twitter API,并且我正在观察一些对我来说似乎很奇怪的行为。
如果我运行以下代码...
from twython import Twython
from random import randint
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) # In the actual code, I obviously assign these, but I can't disclose them here, so the code won't work...
user_id = randint(1,250000000)
twitter_user = twitter.lookup_user(user_id)
我得到这个错误。
Traceback (most recent call last):
File "Twitter_API_Extraction.py", line 76, in <module>
twitter_user = twitter.lookup_user(user_id) # returns a list of dictionaries with all the users requested
TypeError: lookup_user() takes exactly 1 argument (2 given)
Twython 文档表明我只需要传递用户 ID 或屏幕名称 ( https://twython.readthedocs.org/en/latest/api.html )。一些谷歌搜索表明这个错误通常意味着我需要将self作为第一个参数传递,但我不太明白为什么。
但是,如果我改用以下作业...
twitter_user = twitter.lookup_user(user_id = randint(1,250000000))
一切都是玫瑰。我不知道为什么会这样,当我尝试使用相同的 lookup_user 函数访问关注者时,这是代码后面的一个问题。
任何有关触发此错误的原因以及我如何通过函数调用中的赋值绕过它的任何说明都将不胜感激!