【问题标题】:Can't create a bot with Tweepy in Python. Traceback (most recent call last) Error appears无法在 Python 中使用 Tweepy 创建机器人。 Traceback (most recent call last) 出现错误
【发布时间】:2022-12-07 09:58:15
【问题描述】:

我想创建一个推特机器人来测试一下。

我写了这段代码:

auth = tweepy.OAuthHandler(api_key, api_key_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth, wait_on_rate_limit=True)

api.create_friendship("******")

(显然我还创建了像 api_key = "..." 这样的变量)

但我从控制台中得到的唯一信息是:

Traceback (most recent call last):
  File "C:\Users\Anwender\PycharmProjects\TwitterBot\main.py", line 13, in <module>
    api.create_friendship("******")
  File "C:\Users\Anwender\PycharmProjects\TwitterBot\venv\lib\site-packages\tweepy\api.py", line 46, in wrapper
    return method(*args, **kwargs)
TypeError: API.create_friendship() takes 1 positional argument but 2 were given

有人能告诉我怎么了吗? Tweepy 已安装。在我安装 PyCharm 本身而不是 cmd 之前遇到了一些问题。

当我第一次安装 tweepy 时,我将 pip 升级到最新版本。 不知道是不是这里的问题。

【问题讨论】:

    标签: python twitter bots tweepy traceback


    【解决方案1】:

    这可能是由于create_friendship() 中缺少关键字参数。

    您需要确定要传递的参数。例如,如果“*****”是用户 ID,则:

    api.create_friendship(user_id = "******")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 2014-11-17
      • 2022-01-18
      • 2014-05-25
      • 2023-01-07
      • 1970-01-01
      相关资源
      最近更新 更多