kudos
kudos

Reputation: 23

mentions_timeline() takes 1 positional argument but 2 were given

I can't seem to be getting this to work. I've watched so many videos and have read through docs. I just can NOT get this working. I'm trying to get my Twitter bot working

Code

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)

Error

  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

Upvotes: 2

Views: 747

Answers (3)

Paul Singh
Paul Singh

Reputation: 1

I was having the same issue I passed since_id = read_last_seen(FILE_NAME) and it worked

Upvotes: 0

Harmon758
Harmon758

Reputation: 5157

Tweepy v4.0.0 changed API.mentions_timeline to not accept any positional arguments.
The 1 positional argument being referred to in the error is self.
You can pass read_last_seen(FILE_NAME) as the since_id keyword argument instead.

This is also covered in a FAQ section in Tweepy's documentation.

Upvotes: 3

Shine
Shine

Reputation: 588

There's some code missing so I need to make an assumption but from the documentation on tweepy the function signature for mentions_timeline is:

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

This * indicates that all arguments after the symbol have to be passed as key word arguments. E.g. this should normally work:

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

But the signature does not indicate a tweet_mode exists?

Upvotes: 0

Related Questions