post 请求失败后如何自动重试
How can i make an automaticly retry after post request fails
我需要编码 Python 在连接到网站失败后重试,比如当我尝试 post 一个请求并且它失败 python 自动重试。我使用 post 请求,当 python 发送请求失败时,代码将停止,但我需要重试!
希望有人能帮助我
谢谢
这样做,
while True:
try:
session.post(cart, data=payload, proxies=proxy)
break
except:
continue
主循环是一个while True循环,除非成功完成try语句,否则它将永远持续下去。只要有异常,就会回到while循环的顶部。
我需要编码 Python 在连接到网站失败后重试,比如当我尝试 post 一个请求并且它失败 python 自动重试。我使用 post 请求,当 python 发送请求失败时,代码将停止,但我需要重试!
希望有人能帮助我 谢谢
这样做,
while True:
try:
session.post(cart, data=payload, proxies=proxy)
break
except:
continue
主循环是一个while True循环,除非成功完成try语句,否则它将永远持续下去。只要有异常,就会回到while循环的顶部。