@@ -143,9 +143,9 @@ def __send_request(self, path, method="GET", params=None, use_token=True, use_js
143143 headers = {'Authorization' : 'Bearer {}' .format (self .__token )}
144144 else :
145145 headers = {}
146- if use_json_content_type and params :
147- headers ['Content-Type' ] = 'application/json'
148- params = json .dumps (params )
146+ # if use_json_content_type and params:
147+ headers ['Content-Type' ] = 'application/json'
148+ params = json .dumps (params )
149149
150150 if method == "POST" :
151151 response = requests .post (url , headers = headers , data = params )
@@ -178,18 +178,16 @@ def __handle_result(self, data):
178178 """
179179 try :
180180 result = data .json ()
181+ errors = {}
181182 except :
182- result = {
183+ result = {}
184+ errors = {
183185 'is_error' : True ,
184186 'http_code' : data .status_code ,
185187 'message' : "Response is empty, invalid or not JSON."
186188 }
187189
188190 if data .ok :
189- errors = {
190- 'is_error' : False ,
191- 'http_code' : data .status_code
192- }
193191 logger .debug ("Handle result: {}" .format (result , ))
194192 else :
195193 errors = {
@@ -201,11 +199,11 @@ def __handle_result(self, data):
201199 elif data .status_code == 500 :
202200 errors [
'message' ]
= "Whoops, looks like something went wrong on the server. Please contact with out support [email protected] ." 203201
204- logger .debug ("Handle result: {}" .format (errors , ))
202+ logger .debug ("Handle result: {}" .format (errors , ))
205203
206204 # return object that maintains backward-compatibility
207- result . update ( errors )
208- result . update ( {'data' : result . copy ()})
205+ if not data . ok :
206+ result = {'data' : errors }
209207 return result
210208
211209 def __handle_error (self , custom_message = None ):
0 commit comments