提交 1e80a2a5 编写于 作者: W wizardforcel

为 requests 添加 retry

上级 11173ff2
......@@ -69,4 +69,14 @@ def read_in_chunk(fname, size=4 * 1024 * 1024, cnt=-1):
idx += 1
def log(message):
print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] {message}")
\ No newline at end of file
print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] {message}")
def request_retry(method, url, retry=5, **kwargs):
for i in range(retry):
try:
return requests.request(method, url, **kwargs)
except Exception as ex:
if i == retry - 1: raise ex
get_retry = lambda url, retry=5, **kwargs: request_retry('GET', url, retry, **kwargs)
post_retry = lambda url, retry=5, **kwargs: request_retry('POST', url, retry, **kwargs)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册