From c38c4051bcec8b8ee2aa87a9a3723602feec35fe Mon Sep 17 00:00:00 2001 From: jayzhenghan Date: Thu, 24 Sep 2020 18:27:54 +0800 Subject: [PATCH 1/4] fix bug --- qcloud_cos/cos_client.py | 10 ++++++++++ qcloud_cos/streambody.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index 838ce6f2..775b38f4 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -237,7 +237,12 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, **kwar elif bucket is not None: kwargs['headers']['Host'] = self._conf.get_host(bucket) kwargs['headers'] = format_values(kwargs['headers']) + + file_position = None if 'data' in kwargs: + body = kwargs['data'] + if hasattr(body, 'tell') and hasattr(body, 'seek') and hasattr(body, 'read'): + file_position = body.tell() # 记录文件当前位置 kwargs['data'] = to_bytes(kwargs['data']) if self._conf._ip is not None and self._conf._scheme == 'https': kwargs['verify'] = False @@ -262,6 +267,11 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, **kwar except Exception as e: # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误 logger.exception('url:%s, retry_time:%d exception:%s' % (url, j, str(e))) if j < self._retry: + if file_position is not None: + try: + kwargs['data'].seek(file_position) + except IOError as ioe: + raise CosClientError(str(ioe)) continue raise CosClientError(str(e)) diff --git a/qcloud_cos/streambody.py b/qcloud_cos/streambody.py index e3404af2..b394aa97 100644 --- a/qcloud_cos/streambody.py +++ b/qcloud_cos/streambody.py @@ -70,9 +70,9 @@ def pget_stream_to_file(self, fdst, offset, expected_len, auto_decompress=False) """保存流到本地文件的offset偏移""" self._read_len = 0 fdst.seek(offset, 0) - + chunk_size = 1024 * 1024 while 1: - chunk = self.read(1024, auto_decompress) + chunk = self.read(chunk_size, auto_decompress) if not chunk: break self._read_len += len(chunk) From ee23b308754848f6be82722a18580a34255c009e Mon Sep 17 00:00:00 2001 From: jayzhenghan Date: Thu, 24 Sep 2020 18:36:12 +0800 Subject: [PATCH 2/4] fix bug --- qcloud_cos/version.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qcloud_cos/version.py b/qcloud_cos/version.py index 42a3b009..7a4eeffd 100644 --- a/qcloud_cos/version.py +++ b/qcloud_cos/version.py @@ -1,2 +1,2 @@ -__version__ = '5.1.8.5' +__version__ = '5.1.8.6' diff --git a/setup.py b/setup.py index 6e7fc148..74b15013 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def long_description(): setup( name='cos-python-sdk-v5', - version='1.8.5', + version='1.8.6', url='https://www.qcloud.com/', license='MIT', author='tiedu, lewzylu, channingliu', From 96f07dc6b1733c3834cae7ea72757774b26d4a69 Mon Sep 17 00:00:00 2001 From: jayzhenghan Date: Thu, 24 Sep 2020 19:32:52 +0800 Subject: [PATCH 3/4] fix bug --- qcloud_cos/cos_client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index 775b38f4..7a9a8e90 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -14,6 +14,7 @@ from requests import Request, Session from datetime import datetime from six.moves.urllib.parse import quote, unquote, urlencode +from six import text_type, binary_type from hashlib import md5 from dicttoxml import dicttoxml from .streambody import StreamBody @@ -266,7 +267,15 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, **kwar break except Exception as e: # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误 logger.exception('url:%s, retry_time:%d exception:%s' % (url, j, str(e))) - if j < self._retry: + can_retry = False + if 'data' in kwargs: + body = kwargs[data] + if hasattr(body, 'tell') and hasattr(body, 'seek') and hasattr(body, 'read'): + can_retry = True + elif isinstance(body, unicode) or isinstance(body, text_type) or isinstance(body, binary_type): + can_retry = True + + if j < self._retry and can_retry: if file_position is not None: try: kwargs['data'].seek(file_position) From 2a1cb76c54334bc65fae28c3c8ad4375e708c1ae Mon Sep 17 00:00:00 2001 From: jayzhenghan Date: Thu, 24 Sep 2020 19:36:20 +0800 Subject: [PATCH 4/4] fix bug --- qcloud_cos/cos_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index 7a9a8e90..74f93538 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -272,7 +272,7 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, **kwar body = kwargs[data] if hasattr(body, 'tell') and hasattr(body, 'seek') and hasattr(body, 'read'): can_retry = True - elif isinstance(body, unicode) or isinstance(body, text_type) or isinstance(body, binary_type): + elif isinstance(body, text_type) or isinstance(body, binary_type): can_retry = True if j < self._retry and can_retry: