From 8c9922a05f2a008e37dc55f7c12e40522ad88c2a Mon Sep 17 00:00:00 2001 From: tiedu Date: Fri, 19 Jul 2019 18:20:09 +0800 Subject: [PATCH 1/4] modify ut --- ut/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ut/test.py b/ut/test.py index fb98f7ef..af6bc446 100644 --- a/ut/test.py +++ b/ut/test.py @@ -650,7 +650,7 @@ def test_upload_file_multithreading(): Bucket=test_bucket, Key=file_name, LocalFilePath=file_name, - MAXThread=10, + MAXThread=5, EnableMD5=True ) ed = time.time() # 记录结束时间 From 66d5b28d3e95924b8e556fbdbd5badbd1abb4b95 Mon Sep 17 00:00:00 2001 From: tiedu Date: Thu, 25 Jul 2019 12:56:47 +0800 Subject: [PATCH 2/4] fix retry --- qcloud_cos/cos_client.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index a56a27bb..f2658111 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -209,8 +209,8 @@ def send_request(self, method, url, bucket, timeout=30, **kwargs): kwargs['headers'] = format_values(kwargs['headers']) if 'data' in kwargs: kwargs['data'] = to_bytes(kwargs['data']) - try: - for j in range(self._retry): + for j in range(self._retry + 1): + try: if method == 'POST': res = self._session.post(url, timeout=timeout, **kwargs) elif method == 'GET': @@ -223,9 +223,11 @@ def send_request(self, method, url, bucket, timeout=30, **kwargs): res = self._session.head(url, timeout=timeout, **kwargs) if res.status_code < 400: # 2xx和3xx都认为是成功的 return res - except Exception as e: # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误 - logger.exception('url:%s, exception:%s' % (url, str(e))) - raise CosClientError(str(e)) + except Exception as e: # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误 + logger.exception('url:%s, retry_time:%d exception:%s' % (url, j, str(e))) + if j < self._retry: + continue + raise CosClientError(str(e)) if res.status_code >= 400: # 所有的4XX,5XX都认为是COSServiceError if method == 'HEAD' and res.status_code == 404: # Head 需要处理 From b1781df78d8343c8d0a81511171328eab78b0733 Mon Sep 17 00:00:00 2001 From: tiedu Date: Thu, 25 Jul 2019 13:11:51 +0800 Subject: [PATCH 3/4] no longer support python 2.6 --- .travis.yml | 1 - ut/test.py | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6044fd53..92611011 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ sudo: false language: python python: -- '2.6' - '2.7' - '3.5' - '3.6' diff --git a/ut/test.py b/ut/test.py index af6bc446..5314a9aa 100644 --- a/ut/test.py +++ b/ut/test.py @@ -24,7 +24,7 @@ SecretId=SECRET_ID, SecretKey=SECRET_KEY, ) -client = CosS3Client(conf) +client = CosS3Client(conf, retry=3) def _create_test_bucket(test_bucket): @@ -638,6 +638,18 @@ def test_list_multipart_uploads(): ) +def test_upload_file_from_buffer(): + import io + data = io.BytesIO(6*1024*1024*'A') + response = client.upload_file_from_buffer( + Bucket=test_bucket, + Key='test_upload_from_buffer', + Body=data, + MaxBufferSize=5, + PartSize=1 + ) + + def test_upload_file_multithreading(): """根据文件大小自动选择分块大小,多线程并发上传提高上传速度""" file_name = "thread_1GB" From b0f0eb2e96d4cc22976a1e21b7fc74da36c23ef4 Mon Sep 17 00:00:00 2001 From: tiedu Date: Thu, 25 Jul 2019 13:31:10 +0800 Subject: [PATCH 4/4] publish 1.7.2 --- qcloud_cos/version.py | 2 +- ut/test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qcloud_cos/version.py b/qcloud_cos/version.py index 3ba8b1cf..72954835 100644 --- a/qcloud_cos/version.py +++ b/qcloud_cos/version.py @@ -1,2 +1,2 @@ -__version__ = '5.1.7.1' +__version__ = '5.1.7.2' diff --git a/ut/test.py b/ut/test.py index 5314a9aa..32cc1c2b 100644 --- a/ut/test.py +++ b/ut/test.py @@ -640,7 +640,7 @@ def test_list_multipart_uploads(): def test_upload_file_from_buffer(): import io - data = io.BytesIO(6*1024*1024*'A') + data = io.BytesIO(6*1024*1024*b'A') response = client.upload_file_from_buffer( Bucket=test_bucket, Key='test_upload_from_buffer',