Skip to content

Commit c24561b

Browse files
committed
fix(download): 修复下载方法中在下载文件 HTTP 请求未返回 Content-Length 头部导致下载方法失败的问题
1 parent d830a79 commit c24561b

6 files changed

Lines changed: 37 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [0.6.2](https://github.com/teambge/bge-python-sdk/compare/v0.6.1...v0.6.2) (2024-07-22)
2+
3+
4+
### Bug Fixes
5+
6+
* **download:** 修复下载方法中在下载文件 HTTP 请求未返回 Content-Length 头部导致下载方法失败的问题 ([5a33e8b](https://github.com/teambge/bge-python-sdk/commit/5a33e8bfa7174510eeb2ab1951bebc3220e067a3))
7+
8+
9+
110
## [0.6.1](https://github.com/teambge/bge-python-sdk/compare/v0.6.0...v0.6.1) (2023-12-04)
211

312

bgesdk/client.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -890,18 +890,30 @@ def download(self, object_name, fp, region=None,
890890
timeout = self.timeout
891891
try:
892892
with requests.get(url, stream=True, timeout=timeout) as r:
893-
total = int(r.headers['content-length'])
894-
for chunk in r.iter_content(chunk_size):
895-
size += len(chunk)
896-
eq_size = int(size * prog_size / total)
897-
equal_s = '=' * eq_size
898-
blank_s = ' ' * (prog_size - eq_size)
899-
progress = '>'.join((equal_s, blank_s))
900-
percent = '%.2f%%' % float(size / total * 100)
901-
sys.stdout.write(
902-
'\r\t%s [%s]' % (percent.rjust(7), progress)
903-
)
904-
fp.write(chunk)
893+
total = r.headers.get('content-length')
894+
if total is not None:
895+
total = int(total)
896+
for chunk in r.iter_content(chunk_size):
897+
size += len(chunk)
898+
eq_size = int(size * prog_size / total)
899+
equal_s = '=' * eq_size
900+
blank_s = ' ' * (prog_size - eq_size)
901+
progress = '>'.join((equal_s, blank_s))
902+
percent = '%.2f%%' % float(size / total * 100)
903+
sys.stdout.write(
904+
'\r\t%s [%s]' % (percent.rjust(7), progress)
905+
)
906+
sys.stdout.flush()
907+
fp.write(chunk)
908+
else:
909+
for chunk in r.iter_content(chunk_size):
910+
size += len(chunk)
911+
sys.stdout.write(
912+
'\r\t已下载文件:%s' % human_byte(size).ljust(7)
913+
)
914+
sys.stdout.flush()
915+
fp.write(chunk)
916+
sys.stdout.write('\n')
905917
flush_func = getattr(fp, 'flush', None)
906918
if flush_func:
907919
flush_func()

bgesdk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#-*- coding: utf-8 -*-
22

3-
__version__ = '0.6.1'
3+
__version__ = '0.6.2'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bge-python-sdk",
3-
"version": "0.6.1",
3+
"version": "0.6.2",
44
"scripts": {
55
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
66
"init_changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = bge-python-sdk
3-
version = 0.6.1
3+
version = 0.6.2
44
description = 可用于调用 BGE 开放平台的相关接口。
55
long_description = file: README.md
66
long_description_content_type = text/markdown

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sonar.projectName=bge-python-sdk
2-
sonar.projectVersion=0.6.1
2+
sonar.projectVersion=0.6.2
33
sonar.host.url=https://sonarqube.omgut.com
44
sonar.projectKey=bge_bge-python-sdk_AX6jmT2y6I6LwTlVf_Z1
55
sonar.links.homepage=https://github.com/teambge/bge-python-sdk

0 commit comments

Comments
 (0)