Skip to content

Commit f7c638d

Browse files
authored
Merge pull request #932 from Agossi/master
Fix for Issue #931
2 parents 78ce303 + c807b7c commit f7c638d

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/main/resources/handlebars/python/api_client.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,14 @@ class ApiClient(object):
530530
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
531531
content_disposition).group(1)
532532
path = os.path.join(os.path.dirname(path), filename)
533-
534-
with open(path, "wb") as f:
535-
f.write(response.data)
536-
533+
response_data = response.data
534+
with open(path, "wb") as f:
535+
if isinstance(response_data, str):
536+
# change str to bytes so we can write it
537+
response_data = response_data.encode('utf-8')
538+
f.write(response_data)
539+
else:
540+
f.write(response_data)
537541
return path
538542

539543
def __deserialize_primitive(self, data, klass):

src/main/resources/handlebars/python/rest.mustache

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ class RESTClientObject(object):
207207
if _preload_content:
208208
r = RESTResponse(r)
209209

210-
# In the python 3, the response.data is bytes.
211-
# we need to decode it to string.
212-
if six.PY3:
213-
r.data = r.data.decode('utf8')
214-
215210
# log response body
216211
logger.debug("response body: %s", r.data)
217212

0 commit comments

Comments
 (0)