gpt4 book ai didi

重试运行函数的 Pythonic 方式

转载 作者:太空狗 更新时间:2023-10-30 01:41:33 24 4
gpt4 key购买 nike

<分区>

Python Professinal 如何重试运行将请求 Web 服务的函数(Web 服务有时会失败)

函数:

def some_request(uri):
try:
req = requests.post('http://someuri.com', {'test': 'yes'})
except Exception as e:
return False
return {'id': req.json()['value'], 'other': req.json()['other']}

您使用 while 或其他 python 惯用语处理重试?

给我一​​个关于如何以正确的方式做到这一点的线索。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com