From c24561b5ef34e07199ccc02c230225918b6c4c63 Mon Sep 17 00:00:00 2001 From: leafcoder Date: Mon, 22 Jul 2024 14:54:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(download):=20=E4=BF=AE=E5=A4=8D=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=96=B9=E6=B3=95=E4=B8=AD=E5=9C=A8=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=20HTTP=20=E8=AF=B7=E6=B1=82=E6=9C=AA?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=20Content-Length=20=E5=A4=B4=E9=83=A8?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E4=B8=8B=E8=BD=BD=E6=96=B9=E6=B3=95=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 +++++++++ bgesdk/client.py | 36 ++++++++++++++++++++++++------------ bgesdk/version.py | 2 +- package.json | 2 +- setup.cfg | 2 +- sonar-project.properties | 2 +- 6 files changed, 37 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7998e68..c1a0227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [0.6.2](https://github.com/teambge/bge-python-sdk/compare/v0.6.1...v0.6.2) (2024-07-22) + + +### Bug Fixes + +* **download:** 修复下载方法中在下载文件 HTTP 请求未返回 Content-Length 头部导致下载方法失败的问题 ([5a33e8b](https://github.com/teambge/bge-python-sdk/commit/5a33e8bfa7174510eeb2ab1951bebc3220e067a3)) + + + ## [0.6.1](https://github.com/teambge/bge-python-sdk/compare/v0.6.0...v0.6.1) (2023-12-04) diff --git a/bgesdk/client.py b/bgesdk/client.py index 1f903ca..01b0300 100644 --- a/bgesdk/client.py +++ b/bgesdk/client.py @@ -890,18 +890,30 @@ def download(self, object_name, fp, region=None, timeout = self.timeout try: with requests.get(url, stream=True, timeout=timeout) as r: - total = int(r.headers['content-length']) - for chunk in r.iter_content(chunk_size): - size += len(chunk) - eq_size = int(size * prog_size / total) - equal_s = '=' * eq_size - blank_s = ' ' * (prog_size - eq_size) - progress = '>'.join((equal_s, blank_s)) - percent = '%.2f%%' % float(size / total * 100) - sys.stdout.write( - '\r\t%s [%s]' % (percent.rjust(7), progress) - ) - fp.write(chunk) + total = r.headers.get('content-length') + if total is not None: + total = int(total) + for chunk in r.iter_content(chunk_size): + size += len(chunk) + eq_size = int(size * prog_size / total) + equal_s = '=' * eq_size + blank_s = ' ' * (prog_size - eq_size) + progress = '>'.join((equal_s, blank_s)) + percent = '%.2f%%' % float(size / total * 100) + sys.stdout.write( + '\r\t%s [%s]' % (percent.rjust(7), progress) + ) + sys.stdout.flush() + fp.write(chunk) + else: + for chunk in r.iter_content(chunk_size): + size += len(chunk) + sys.stdout.write( + '\r\t已下载文件:%s' % human_byte(size).ljust(7) + ) + sys.stdout.flush() + fp.write(chunk) + sys.stdout.write('\n') flush_func = getattr(fp, 'flush', None) if flush_func: flush_func() diff --git a/bgesdk/version.py b/bgesdk/version.py index 6ba7312..b37c624 100644 --- a/bgesdk/version.py +++ b/bgesdk/version.py @@ -1,3 +1,3 @@ #-*- coding: utf-8 -*- -__version__ = '0.6.1' +__version__ = '0.6.2' diff --git a/package.json b/package.json index 73ee188..5e88ae4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bge-python-sdk", - "version": "0.6.1", + "version": "0.6.2", "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "init_changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0" diff --git a/setup.cfg b/setup.cfg index f8f6f65..33555a6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = bge-python-sdk -version = 0.6.1 +version = 0.6.2 description = 可用于调用 BGE 开放平台的相关接口。 long_description = file: README.md long_description_content_type = text/markdown diff --git a/sonar-project.properties b/sonar-project.properties index 9cbf78a..7a982a1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,5 @@ sonar.projectName=bge-python-sdk -sonar.projectVersion=0.6.1 +sonar.projectVersion=0.6.2 sonar.host.url=https://sonarqube.omgut.com sonar.projectKey=bge_bge-python-sdk_AX6jmT2y6I6LwTlVf_Z1 sonar.links.homepage=https://github.com/teambge/bge-python-sdk