Skip to content

Commit 52dda2e

Browse files
committed
sanatize the returned results - just in case API is messed up
1 parent 080733b commit 52dda2e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Change Log
22

3+
- 2016-12-10 15:39:29 -0800 [080733b](https://github.com/cloudflare/python-cloudflare/commit/080733b58e144670116d7f3ccadf369d599bfc61) CHANGELOG.md pushed to github
34
- 2016-12-10 15:39:01 -0800 [f3d6377](https://github.com/cloudflare/python-cloudflare/commit/f3d637727d74acecd8faf4c9b6d652ee2cff183f) 1.4.1 release
45
- 2016-12-10 15:38:10 -0800 [8c66d32](https://github.com/cloudflare/python-cloudflare/commit/8c66d3253b6f257b61b0116600fb2b3d77e8f0fb) cleanup of yaml print output if yaml package isnt installed
56
- 2016-12-09 16:22:51 -0800 [894ae11](https://github.com/cloudflare/python-cloudflare/commit/894ae11788a2b1997e4f58895d205d1f74ab16f7) Moved walk into CloudFlare class - much cleaner

CloudFlare/cloudflare.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def call_with_certauth(self, method,
7777
params=None, data=None):
7878
""" Cloudflare v4 API"""
7979

80-
if self.certtoken is '':
80+
if self.certtoken is '' or self.certtoken is None:
8181
raise CloudFlareAPIError(0, 'no cert token defined')
8282
headers = {
8383
'X-Auth-User-Service-Key': self.certtoken,
@@ -184,6 +184,27 @@ def _call(self, method, headers,
184184
api_call_part1, api_call_part2, api_call_part3,
185185
identifier1, identifier2,
186186
params, data)
187+
188+
# Sanatize the returned results - just in case API is messed up
189+
if 'success' not in response_data:
190+
if 'errors' in response_data:
191+
if self.logger:
192+
self.logger.debug('Response: missing success value - assuming success = "False"')
193+
response_data['success'] = False
194+
else:
195+
if 'result' not in response_data:
196+
# Only happens on /certificates call - and should be fixed in /certificates API
197+
if self.logger:
198+
self.logger.debug('Response: missing success and error value - assuming success = "False"')
199+
r = response_data
200+
response_data['errors'] = []
201+
response_data['errors'].append(r)
202+
response_data['success'] = False
203+
else:
204+
if self.logger:
205+
self.logger.debug('Response: missing success value - assuming success = "True"')
206+
response_data['success'] = True
207+
187208
if response_data['success'] is False:
188209
errors = response_data['errors'][0]
189210
code = errors['code']

0 commit comments

Comments
 (0)