Skip to content

Commit

Permalink
yet another fix for unicode/utf8 returned JSON data
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Feb 7, 2018
1 parent 99005c1 commit 7c0411c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CloudFlare/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _raw(self, method, headers, parts,
if response_type == 'application/json':
# API says it's JSON; so it better be parsable as JSON
try:
response_data = json.loads(response_data)
response_data = json.loads(response_data.decode('utf-8'))
except ValueError:
if response_data == '':
# This should really be 'null' but it isn't. Even then, it's wrong!
Expand Down
6 changes: 5 additions & 1 deletion cli4/cli4.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,13 @@ def cli4(args):
else:
# anything more complex (dict, list, etc) should be dumped as JSON/YAML
if output == 'json':
sys.stdout.write(json.dumps(results, indent=4, sort_keys=True) + '\n')
# json.dumps(results, sys.stdout, indent=4, sort_keys=True)
# sys.stdout.write('\n')
# sys.stdout.write(json.dumps(results, indent=4, sort_keys=True) + '\n')
try:
print(json.dumps(results, indent=4, sort_keys=True, ensure_ascii=False, encoding='utf8'))
except TypeError as e:
print(json.dumps(results, indent=4, sort_keys=True, ensure_ascii=False))
if output == 'yaml':
sys.stdout.write(yaml.safe_dump(results))

0 comments on commit 7c0411c

Please sign in to comment.