我正在使用此code suggested by alecxe来为字典中的每个用户收集关注者的ID。这是我正在使用的代码:
networkFile = open(r"xxxxx/network%s.txt"% timestr, "w")
for key, value in accounts_alive_dic.iteritems():
print ("main: "+key)
ids = []
for page in tweepy.Cursor(api.followers_ids, screen_name=accounts_alive_dic[key][0]).pages():
try:
ids.extend(page)
time.sleep(60)
print(ids)
except:
ids=[]
print("Second loop exception for key "+key)
for id in ids:
try:
print(key+","+str(id)+'\n')
networkFile.write(key+","+str(id)+'\n')
except:
print("Third loop exception for key "+key)
networkFile.close()
不幸的是,在收集了几个粉丝后,我收到了以下错误消息:
Traceback (most recent call last):
File "<input>", line 4, in <module>
File "/usr/lib/python2.7/site-packages/tweepy/cursor.py", line 75, in next
**self.kargs)
File "/usr/lib/python2.7/site-packages/tweepy/binder.py", line 239, in _call
return method.execute()
File "/usr/lib/python2.7/site-packages/tweepy/binder.py", line 223, in execute
raise TweepError(error_msg, resp)
TweepError: [{u'message': u'Sorry, that page does not exist.', u'code': 34}]
您对导致此错误的原因有什么想法吗?如何解决问题?非常感谢。
答案 0 :(得分:0)
固定。问题是一些用户拥有动态用户名(非常聪明呃?!)。我通过使用用户ID而不是用户名来解决问题。所以现在这行来自我之前的代码:
for page in tweepy.Cursor(api.followers_ids,screen_name=accounts_alive_dic[key][0]).pages()
看起来像:
for page in tweepy.Cursor(api.followers_ids, id=key).pages()
希望这可以帮助那些人。