python API stalling out on followers call

121 views
Skip to first unread message

John Scholvin

unread,
May 8, 2018, 10:43:01 AM5/8/18
to Tumblr API Discussion
I've got a script that has worked forever, which (among other things) pulls the followers for a blog. I had to write some code around it to kind of baby the calls into it, finding out the hard way that you can only request 20 at a time, and you might get fewer than 20 back. What I'm finding is that after a certain number of fetches that changes, the call into followers just never returns. This happens after returning about 600 followers for a blog that has maybe 1200. I upgraded to the latest version of pytumblr and it made no difference. Code is below. Any insight would be appreciated.

import pytumblr
import time

# Authenticate via OAuth
client = pytumblr.TumblrRestClient(
  'xxx',   # consumer key
  'xxx',   # consumer secret
  'xxx',   # oauth token  (27-Dec-2014)
  'xxx'    # oauth secret (27-Dec-2014)
)

block_size = 20
followers = True
verbose = True

if followers:
    users = []
    offset = 0
    while True:
        if verbose:
            print "grabbing followers at", offset
        response = client.followers(blog, limit=block_size, offset=offset)
        try:
            bunch = len(response["users"]) # can be fewer than requewted
        except KeyError:
            bunch = 0
        if verbose:
            print "bunch is", bunch
        if bunch == 0:
            break
        j = 0;
        while j < bunch:
            if verbose:
                print response["users"][j]["name"]
            users.append(response["users"][j]["name"])
            j = j + 1
        offset += bunch
        time.sleep(1) # to give the API a break

Reply all
Reply to author
Forward
0 new messages