diff --git a/BiliDriveEx/util.py b/BiliDriveEx/util.py index 28e539677d652f027a0e0451c8dfa52a7e98b364..b7e5cdfd10c86e68b04fefc7f66ed586f83cb946 100644 --- a/BiliDriveEx/util.py +++ b/BiliDriveEx/util.py @@ -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