get_user() takes 1 positional argument but 2 were given
Question:
I’ve been having issues getting passed this bug, I was wondering If anyone could help. Or could point me in the right direction? I believe the issue may be with API.get_user. But I just cannot find a workaround it.
This script is supposed to read a csv file of Twitter usernames(list.csv) and pull the unique IDs. Then format those IDs into another csv file.(ids.csv)
here is the error I receive when running get_user_ids.py
these lines end up populating in my newly generated ids.csv file.
get_user() takes 1 positional argument but 2 were given
import tweepy
import time
import csv
import sys
consumer_key = "CONSUMER_KEY"
consumer_secret = "CONSUMER_SECRET"
access_token = "ACCESS_TOKEN"
access_token_secret = "ACCESS_TOKEN_SECRET"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
def get_user_ids():
handles = []
with open("list.csv", "r") as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
for elem in row:
handles.extend(elem.strip().split(','))
for handle in handles:
try:
u = api.get_user(handle[1:-1])
time.sleep(6)
print (u._json['id'])
sys.stderr.write(str(u._json['id']) + "n")
except Exception as e:
print (e)
if __name__ == '__main__':
get_user_ids()
Answers:
As shown in the documentation:
API.get_user(*, user_id, screen_name, include_entities)
This means that there are no positional parameters; user_id
and screen_name
are keyword-only parameters, so the argument must explicitly name the correct keyword:
api.get_user(user_id=handle[1:-1])
or
api.get_user(screen_name=handle[1:-1])
Choose the correct one according to how handle[1:-1]
should be interpreted:
user_id
– Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
screen_name
– Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
I’ve been having issues getting passed this bug, I was wondering If anyone could help. Or could point me in the right direction? I believe the issue may be with API.get_user. But I just cannot find a workaround it.
This script is supposed to read a csv file of Twitter usernames(list.csv) and pull the unique IDs. Then format those IDs into another csv file.(ids.csv)
here is the error I receive when running get_user_ids.py
these lines end up populating in my newly generated ids.csv file.
get_user() takes 1 positional argument but 2 were given
import tweepy
import time
import csv
import sys
consumer_key = "CONSUMER_KEY"
consumer_secret = "CONSUMER_SECRET"
access_token = "ACCESS_TOKEN"
access_token_secret = "ACCESS_TOKEN_SECRET"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
def get_user_ids():
handles = []
with open("list.csv", "r") as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
for elem in row:
handles.extend(elem.strip().split(','))
for handle in handles:
try:
u = api.get_user(handle[1:-1])
time.sleep(6)
print (u._json['id'])
sys.stderr.write(str(u._json['id']) + "n")
except Exception as e:
print (e)
if __name__ == '__main__':
get_user_ids()
As shown in the documentation:
API.get_user(*, user_id, screen_name, include_entities)
This means that there are no positional parameters; user_id
and screen_name
are keyword-only parameters, so the argument must explicitly name the correct keyword:
api.get_user(user_id=handle[1:-1])
or
api.get_user(screen_name=handle[1:-1])
Choose the correct one according to how handle[1:-1]
should be interpreted:
user_id
– Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
screen_name
– Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.