【发布时间】:2018-08-13 18:02:49
【问题描述】:
当使用requests 包发送POST 请求时,如何实现5 次重试计数,间隔10 秒。
我找到了很多 GET 请求的示例,而不是 post。
这是我目前正在使用的,有时我会收到 503 错误。如果我收到错误的响应 HTTP 代码,我只需要实现重试。
for x in final_payload:
post_response = requests.post(url=endpoint, data=json.dumps(x), headers=headers)
#Email me the error
if str(post_response.status_code) not in ["201","200"]:
email(str(post_response.status_code))
【问题讨论】:
-
重试与 GET 或 POST 没有特别的关系,因此您应该能够轻松地调整您找到的示例。
-
我过去曾用它来处理来自外部 API pypi.python.org/pypi/retrying的 GET 请求
标签: python python-3.x python-requests