Jose Ramon
Jose Ramon

Reputation: 5386

Retrieve data from klout exception KloutHTTPError

I am trying to retrieve klouID using the kloud python API. I am taking username from mongo database and I am trying to retrieve kloudid using this username. I ve noticed that I can retrieve ids only for some users(they, or some of their follower are registered in klout). Thus I want to create a try - except in order to overcome the raise KloutHTTPError( e, uri) klout.api.KloutHTTPError: ERROR: HTTP Error 404: Not Found error for the users that klout cannot return a kloudid.

My code :

for cursor in collection.find().limit(100):
    name =  cursor['database'].get('name')
    print name
    kloutId = k.identity.klout(screenName=name).get('id')
    score = k.user.score(kloutId=kloutId).get('score')
    print "User's klout score is: %s" % (score)
    # By default all communication is not secure (HTTP). An optional secure parameter
    # can be sepcified for secure (HTTPS) communication
    k = Klout('...', secure=True)
    # Optionally a timeout parameter (seconds) can also be sent with all calls
    score = k.user.score(kloutId=kloutId, timeout=5).get('score')

Upvotes: 0

Views: 197

Answers (1)

Jose Ramon
Jose Ramon

Reputation: 5386

I add the following change and it works fine:

for cursor in collection.find().limit(10000):
    try:
        name =  cursor['user']['name']
        print name.encode('utf-8')
        kloutId = k.identity.klout(screenName=name).get('id')
        score = k.user.score(kloutId=kloutId).get('score')
        print "User's klout score is: %s" % (score)
        # By default all communication is not secure (HTTP). An optional secure parameter
        # can be sepcified for secure (HTTPS) communication
        k = Klout('...', secure=True)
        # Optionally a timeout parameter (seconds) can also be sent with all calls
        score = k.user.score(kloutId=kloutId, timeout=5).get('score')
        counter = counter+1
        except (KloutHTTPError, UnicodeEncodeError) as e:
                        print "Oops!  That was no kloudId found with that name, or unicode exception.  Try again... ", counter

Upvotes: 0

Related Questions