Skip to content

Commit 8eb8c79

Browse files
authored
Fixes download of hdf5 files (#24)
* Save binary responses to file * Upgrade vulnerabilities GHSA-5phf-pp7p-vc2r * Skips decoding
1 parent 6755cd0 commit 8eb8c79

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

osparc/api_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,12 @@ def __deserialize_file(self, response):
556556
content_disposition).group(1)
557557
path = os.path.join(os.path.dirname(path), filename)
558558

559-
with open(path, "w") as f:
560-
f.write(response.data)
559+
try:
560+
with open(path, "w") as f:
561+
f.write(response.data)
562+
except TypeError:
563+
with open(path, "wb") as f:
564+
f.write(response.data)
561565

562566
return path
563567

osparc/rest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ def request(self, method, url, query_params=None, headers=None,
220220
# In the python 3, the response.data is bytes.
221221
# we need to decode it to string.
222222
if six.PY3:
223-
r.data = r.data.decode('utf8')
224-
225-
# log response body
226-
logger.debug("response body: %s", r.data)
223+
try:
224+
r.data = r.data.decode('utf8')
225+
except UnicodeDecodeError:
226+
# NOTE: hdf5 files cannot be decoded
227+
pass
227228

228229
if not 200 <= r.status <= 299:
229230
raise ApiException(http_resp=r)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
NAME = "osparc"
88
VERSION = "0.4.3"
99
API_VERSION = "0.4"
10-
REQUIRES = ["urllib3 >= 1.15", "six >= 1.10", "certifi", "python-dateutil"]
10+
REQUIRES = ["urllib3 >= 1.26.4", "six >= 1.10", "certifi", "python-dateutil"]
1111
README = Path("README.md").read_text()
1212

1313
setup(

0 commit comments

Comments
 (0)