Paolo
Paolo

Reputation: 23

Tweepy user_timeline takes 1 position but 2 were given error

I'm making a bot that prints the Tweets from a specific user using the user_timeline, but it gives me this error when I run it.

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

This is my full code; obviously I deleted the keys and tokens

# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# screen name of the account to be fetched
screen_name = "geeksforgeeks"
  
# fetching the statuses
statuses = api.user_timeline(screen_name)
  
print(str(len(statuses)) + " number of statuses have been fetched.")

Upvotes: 1

Views: 3141

Answers (2)

Harmon758
Harmon758

Reputation: 5157

Tweepy v4.0.0 changed API.user_timeline to not accept any positional arguments.
The 1 positional argument being referred to in the error is self.
You can pass screen_name as the screen_name keyword argument instead.

Upvotes: 0

Hampus Larsson
Hampus Larsson

Reputation: 3100

According to the source-code you have to use keyword-arguments with the method API.user_timeline.

So change this line:

statuses = api.user_timeline(screen_name)

Into:

statuses = api.user_timeline(screen_name=screen_name)

Upvotes: 3

Related Questions