【发布时间】:2017-11-10 18:44:02
【问题描述】:
我正在尝试使用 Tweepy 抓取一些推文,但在数百个请求后连接崩溃并出现以下错误: tweepy.error.TweepError: 发送请求失败:('Connection aborted.', error("(104, 'ECONNRESET')",))
我的代码是这样的:
for status in tweepy.Cursor(api.search,
q="",
count=100,
include_entities=True,
monitor_rate_limit=True,
wait_on_rate_limit=True,
wait_on_rate_limit_notify = True,
retry_count = 5, #retry 5 times
retry_delay = 5, #seconds to wait for retry
geocode ="34.0207489,-118.6926066,100mi", # los angeles
until=until_date,
lang="en").items():
try:
towrite = json.dumps(status._json)
output.write(towrite + "\n")
except Exception, e:
log.error(e)
c+=1
if c % 10000 == 0: # 100 requests, sleep
time.sleep(900) # sleep 15 min
我可以使用 try/except 捕获错误,但我无法从光标崩溃的位置重新启动光标。 有谁知道如何解决此错误,或从上次已知状态重新启动光标?
谢谢!
【问题讨论】:
标签: twitter connection tweepy