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/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 需要处理 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 fb98f7ef..32cc1c2b 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*b'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" @@ -650,7 +662,7 @@ def test_upload_file_multithreading(): Bucket=test_bucket, Key=file_name, LocalFilePath=file_name, - MAXThread=10, + MAXThread=5, EnableMD5=True ) ed = time.time() # 记录结束时间