0

I've written a python script which uses Twython to interact with twitter. It downloads the followers list into a variable (followers), and the list of people I'm following into another variable (friends). It should then automatically follow everybody who follows me, but who I am not yet following.

for fol in followers:
    if fol not in friends:
        twitter.create_friendship(fol)

The error I'm getting is that twitter.create_friendship requires exactly one argument, but it is being given two. I don't see how it is being given two arguments, I can only see the one.

Holloway
  • 6,412
  • 1
  • 26
  • 33
Alex
  • 2,270
  • 3
  • 33
  • 65
  • Here is the documentation for [`create_friendship`](http://twython.readthedocs.org/en/latest/api.html?highlight=create_friendship#twython.Twython.create_friendship) which points to the [`friendships.create`](https://dev.twitter.com/rest/reference/post/friendships/create) documentation. – Cory Kramer Oct 06 '14 at 13:13
  • When you call a function in python, the object you call it on is passed as the first parameter. This is why all class methods take `self` as the first parameter. – Holloway Oct 06 '14 at 13:14

1 Answers1

5

create_friendship() is a bound method, which means it'll take just the self argument. It doesn't take any other positional arguments, but you are passing in fol, giving it two arguments now (self and fol).

The method should be passed keyword arguments instead:

twitter.create_friendship(user_id=fol)

if fol is a user id, or

twitter.create_friendship(screen_name=fol)

if fol is a screen name.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343