gfcapalbo / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

getFollowers: maximum recursion depth #154

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create API with authentication
2. Call for example users = api.GetFollowers('Optimismus1000')

What is the expected output? What do you see instead?

I wanna get all the followers, but I get:

RuntimeError: maximum recursion depth exceeded

What version of the product are you using? On what operating system?

Newest version on win7

Please provide any additional information below.

It seems, that I also get this message, if a user doesn't exist, or if the user 
is protected. The real problem is also that it takes such a long time for the 
code to run it. I really need a fix for that, because I am getting a lot of 
followers and friends for many ids, and it takes so long for that.

Regards

Original issue reported on code.google.com by kill...@gmail.com on 22 Aug 2010 at 12:24

GoogleCodeExporter commented 9 years ago
Sorry, seems that for example following call doesn't work:

users = api.GetFollowers(87053066)

(I am using the cursor paging now)

Original comment by kill...@gmail.com on 22 Aug 2010 at 7:37

GoogleCodeExporter commented 9 years ago
Can someone PLEASE give a working example of using cursors to return all 
followers?
I keep hitting the 100 user returns. It is not paging.

8< -------------

me = api.GetUser("rrdearman")
# work out the # of page calls
numpages = int(math.ceil(me.followers_count/100.0)) 
followerpage = (api.GetFollowers(page=x) for x in range(1,numpages+1))
# loop and get followers
myfollower = (y[z]
  for y in followerpage \
  for z in range(len(y)))

------------->8

Original comment by rick.dea...@gmail.com on 20 Sep 2011 at 2:20

GoogleCodeExporter commented 9 years ago
Got a copy of 0.8.3 which has a fix that allows the GetFollowers() function to 
attempt to get all the followers. Interestingly this seems to make me hit the 
Rate Limit of Twitter.

twitter.TwitterError: Rate limit exceeded. Clients may not make more than 350 
requests per hour.

I have about 3500 followers. Anyone have any suggestions? Paging didn't work, 
and with a version without paging, I hit rate limits.

Any help is greatly appreciated.

Original comment by rick.dea...@gmail.com on 20 Sep 2011 at 7:14

GoogleCodeExporter commented 9 years ago
As long as you don't have a developer API access you can only make a limited 
number of requests per hour.

Original comment by kill...@gmail.com on 20 Sep 2011 at 7:18

GoogleCodeExporter commented 9 years ago
I have re-written the GetFollowers() and it works for me. Someone should check 
it though. I don't know how to (and not really interested in) merging into 
source. I have 3500+ followers and it works a treat for me. This function will 
probably fail if you hit the rate limit of 350 requests. (i.e. you have more 
than 35,000 followers)

=====================
  def GetFollowers(self, cursor=-1, rate_limit=350):
    '''Fetch the sequence of twitter.User instances, one for each follower

    The twitter.Api instance must be authenticated.

    Args:
      cursor:
        Specifies the Twitter API Cursor location to start at. [Optional]
        Note: there are pagination limits.
      rate_limit:
         Specifies the Twitter rate limit. Defaults to 350. Individuals are limited
         to 150

    Returns:
      A sequence of twitter.User instances, one for each follower
    '''
    if not self._oauth_consumer:
      raise TwitterError("twitter.Api instance must be authenticated")
    url = '%s/statuses/followers.json' % self.base_url
    result = []
    rate_check = 1
    while True:
      parameters = { 'cursor': cursor }
      json = self._FetchUrl(url, parameters=parameters)
      data = self._ParseAndCheckTwitter(json)
      result += [User.NewFromJsonDict(x) for x in data['users']]
      if 'next_cursor' in data:
        cursor = data['next_cursor']
        if data['next_cursor'] == 0 or data['next_cursor'] == data['previous_cursor']:
          break
      else:
        break
      if rate_check == rate_limit:
        break
      else:
        rate_check += 1

    return result

====================

Original comment by rick.dea...@gmail.com on 21 Sep 2011 at 2:45