0

我正在尝试使用 kloud python API 检索 klouID。我正在从 mongo 数据库中获取用户名,并且正在尝试使用此用户名检索 kloudid。我注意到我只能为某些用户检索 id(他们或他们的一些追随者在 klout 中注册)。因此,我想创建一个尝试 - 除非为了克服raise KloutHTTPError( e, uri) klout.api.KloutHTTPError: ERROR: HTTP Error 404: Not Found klout 无法返回 kloudid 的用户错误。

我的代码:

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')
4

1 回答 1

0

我添加了以下更改,它工作正常:

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
于 2014-05-08T06:50:08.897 回答