Skip to content

Commit 3cea130

Browse files
author
libertyzhu
committed
重试逻辑fix
1 parent 30d817b commit 3cea130

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

qcloud_cos/cos_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,19 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, ci_req
374374
elif method == 'HEAD':
375375
res = self._session.head(url, timeout=timeout, proxies=self._conf._proxies, **kwargs)
376376
if res.status_code < 400: # 2xx和3xx都认为是成功的
377+
if res.status_code == 301 or res.status_code == 302 or res.status_code == 307:
378+
if j < self._retry and res.headers['x-cos-request-id'] == '' \
379+
and not domain_switched and self._conf._auto_switch_domain_on_retry and self._conf._ip is None:
380+
url = switch_hostname_for_url(url)
381+
domain_switched = True
382+
continue
377383
return res
378384
elif res.status_code < 500: # 4xx 不重试
385+
if j < self._retry and res.headers['x-cos-request-id'] == '' \
386+
and not domain_switched and self._conf._auto_switch_domain_on_retry and self._conf._ip is None:
387+
url = switch_hostname_for_url(url)
388+
domain_switched = True
389+
continue
379390
break
380391
else:
381392
if j < self._retry and client_can_retry(file_position, **kwargs):

0 commit comments

Comments
 (0)