Skip to content

Commit 722f2c2

Browse files
wallecanfabianvf
authored andcommitted
Do not decode response data in Python2 (#225)
response data is already str in Python2 so it doesn't need to be decoded. Furthermore, as decode() uses ascii by default in PY2, it breaks in case of a non-ascii character the response. Just mimic what kubernetes do in https://github.com/kubernetes-client/python/blob/master/kubernetes/client/rest.py#L216 Fix #224 (cherry picked from commit 8e3a2e9)
1 parent 9e660c1 commit 722f2c2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

openshift/dynamic/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import copy
55
import json
66
from functools import partial
7+
from six import PY2
78

89
import yaml
910
from pprint import pformat
@@ -50,10 +51,14 @@ def serialize(resource, response):
5051
try:
5152
return ResourceInstance(resource, load_json(response))
5253
except ValueError:
53-
return response.data.decode()
54+
if PY2:
55+
return response.data
56+
return response.data.decode('utf8')
5457

5558
def load_json(response):
56-
return json.loads(response.data.decode())
59+
if PY2:
60+
return json.loads(response.data)
61+
return json.loads(response.data.decode('utf8'))
5762

5863

5964
class DynamicClient(object):

0 commit comments

Comments
 (0)