我尝试使用kloud python API检索klouID。我正在从mongo数据库中获取用户名,并尝试使用此用户名检索kloudid。我注意到我只能为一些用户检索id(他们或他们的一些追随者在klout注册)。因此,我想创建一个try-except,以克服klout无法返回kloudid的raise KloutHTTPError( e, uri)
klout.api.KloutHTTPError: ERROR: HTTP Error 404: Not Found
错误。在
我的代码:
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')
我添加了以下更改,效果很好:
相关问题 更多 >
编程相关推荐