【发布时间】:2018-04-19 00:13:13
【问题描述】:
我正在使用 Python 和 Tweepy 编写一个基本程序,以获取 Twitter 屏幕名称列表并下拉相应的用户 ID。我已经实现了速率限制器并且程序可以工作,但是当它遇到我的异常处理时事情就崩溃了。它告诉我 X 中的屏幕名称在等待 15 分钟后不存在。我需要异常处理,因为 Tweepy 在运行时经常遇到问题。我在这里做错了什么?
f = open('output2.txt', 'w')
while True:
for x in HandleList1:
try:
u = api.get_user(id = x)
print >> f, u.id
except tweepy.TweepError:
print "We just hit an error, waiting for 15min and then reconnecting..."
time.sleep(60*15)
u = api.get_user(id = x)
print >> f, u.id
except StopIteration:
print "Stopping the iteration and processing the results!"
break
f.close()
【问题讨论】:
标签: python loops twitter exception-handling tweepy