我正在尝试使用K头python检索klouID。我从mongo数据库中获取用户名,并试图使用这个用户名检索kloudid。我注意到,我只能为某些用户检索I(他们或他们的一些追随者在klout中注册)。因此,我想要创建一个尝试--除非是为了克服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')发布于 2014-05-08 06:50:08
我添加了以下更改,效果很好:
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... ", counterhttps://stackoverflow.com/questions/23516357
复制相似问题