mentions_timeline() 采用 1 个位置参数,但给出了 2 个

mentions_timeline() takes 1 positional argument but 2 were given

我似乎无法让它工作。我看过很多视频并阅读了文档。我就是无法正常工作。我正在尝试让我的 Twitter 机器人正常工作

代码

FILE_NAME = 'last_seen.txt'

def read_last_seen(FILE_NAME):
    file_read = open(FILE_NAME, 'r')
    last_seen_id = int(file_read.read().strip())
    file_read.close()
    return last_seen_id

def store_last_seen(FILE_NAME, last_seen_id):
    file_write = open(FILE_NAME, 'w')
    file_write.write(str(last_seen_id))
    file_write.close()
    return

def reply():
    tweets = api.mentions_timeline(read_last_seen(FILE_NAME), tweet_mode='extended')
    for tweet in reversed(tweets):
        if '@MrGoodnightBot' in tweet.full_text.lower():
            print(str(tweet.id) + ' - ' + tweet.full_text)
            api.update_status("@" + tweet.user.screen_name + " testing auto reply/like/retweet", tweet.id)
            api.create_favorite(tweet.id)
            api.retweet(tweet.id)
            api.create_friendship(tweet.user.id)
            store_last_seen(FILE_NAME, tweet.id)

while True:
    reply()
    time.sleep(1)

错误

  File "E:\Twitter Bot\bot.py", line 29, in reply
    tweets = api.mentions_timeline(read_last_seen(FILE_NAME), tweet_mode='extended')
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39-32\lib\site-packages\tweepy\api.py", line 33, in wrapper
    return method(*args, **kwargs)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39-32\lib\site-packages\tweepy\api.py", line 46, in wrapper
    return method(*args, **kwargs)
TypeError: mentions_timeline() takes 1 positional argument but 2 were given

缺少一些代码,所以我需要做一个假设,但是从 documentation on tweepy 来看,mentions_timeline 的函数签名是:

API.mentions_timeline(*, count, since_id, max_id, trim_user, include_entities)

这个*表示符号之后的所有参数都作为关键字参数传递。例如。这应该正常工作:

tweets = api.mentions_timeline(count=read_last_seen(FILE_NAME), tweet_mode='extended')

但是签名不表示tweet_mode存在?

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

a FAQ section in Tweepy's documentation.

中也有介绍

我遇到了同样的问题,我通过了 since_id = read_last_seen(FILE_NAME) 并且有效