python - python等待并重试当前迭代
问题描述
感谢您抽时间阅读。
我从 GitHub API 迭代地提取数据以获取一些存储库的名称和组织
for i in repoID: #get names of repos
response= requests.get('https://api.github.com/repositories/{}'.format(i),headers=headers)
print(i)
if 'full_name' in response.json():
repokey[str(i)]=response.json()['full_name']
else :
print('ratelimit reached for {}, waiting 120 sec'.format(i))
time.sleep(120)
continue
在继续下一次迭代之前,它会等待一定的时间。但我想在等待后重试达到 API 速率限制的当前迭代。
有没有办法可以做到这一点?
解决方案
使用 awhile
而不是遍历组件本身,这样您就可以返回。
i = 0
while i < len(repoID):
previously_i = repoID[i]
# your stuff
i+=1
if limit:
i-=1
推荐阅读
- android - Flutter AppAuth:在应用程序中启动url时,有没有办法隐藏url地址和底部导航栏?
- python - 具有标量值的 pd.DataFrame
- nuxt.js - Nuxt.js 配置重用已加载的字段
- reactjs - 执行 Material Ui 时出错
- c# - 位移限制?
- google-cloud-platform - 无法在 Google Cloud Platform 中创建 Jupyter 笔记本实例
- hybris - 使用 ImpEx 多次导出同一行
- reactjs - useEffect 清理函数 Typescript 错误:不可分配给“EffectCallback”类型的参数
- exception - c# wpf 如何捕获 FirestoreChangeListener 异常
- django-rest-framework - dj-rest-auth 与 Django ReST 框架 JSON API 不兼容?