Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 231b7a7

Browse files
committed
handle zero length content responses (normally 204 returns to delete)
1 parent ed08910 commit 231b7a7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _raw(self, method, headers, parts, identifiers, params, data_str, data_json,
403403
identifiers,
404404
params, data_str, data_json, files)
405405

406-
if response_code not in [requests_codes.ok, requests_codes.created, requests_codes.accepted]:
406+
if response_code not in [requests_codes.ok, requests_codes.created, requests_codes.accepted, requests_codes.no_content]:
407407
# 3xx & 4xx errors (5xx's handled above)
408408
response_data = {'success': False,
409409
'errors': [{'code': response_code, 'message':'HTTP response code %d' % response_code}],
@@ -461,7 +461,11 @@ def _raw(self, method, headers, parts, identifiers, params, data_str, data_json,
461461
# return binary
462462
return {'success': True, 'result': response_data}
463463
try:
464-
response_data = json.loads(response_data)
464+
if response_data == '':
465+
# This should really be 'null' but it isn't. Even then, it's wrong!
466+
response_data = None
467+
else:
468+
response_data = json.loads(response_data)
465469
except ValueError:
466470
# So it wasn't JSON - moving on as if it's text!
467471
pass
@@ -498,7 +502,11 @@ def _raw(self, method, headers, parts, identifiers, params, data_str, data_json,
498502
# return binary
499503
return {'success': True, 'result': response_data}
500504
try:
501-
response_data = json.loads(response_data)
505+
if response_data == '':
506+
# This should really be 'null' but it isn't. Even then, it's wrong!
507+
response_data = None
508+
else:
509+
response_data = json.loads(response_data)
502510
except ValueError:
503511
# So it wasn't JSON - moving on as if it's text!
504512
pass

0 commit comments

Comments
 (0)