Skip to content

Commit

Permalink
support both python2's non-ascii unicode literals and utf-encoded str…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
Adam Maris committed Nov 25, 2019
1 parent 49daf9d commit f109746
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cortexutils/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ def __write_output(self, data, ensure_ascii=False):

f_output = open('%s/output/output.json' % self.job_directory, mode='w')

if not ensure_ascii:
f_output = codecs.getwriter('utf-8')(f_output, 'strict')
try:
json.dump(data, f_output, ensure_ascii=ensure_ascii)
except UnicodeEncodeError:
f_output.seek(0)
f_writer = codecs.getwriter('utf-8')(f_output, 'strict')
json.dump(data, f_writer, ensure_ascii=ensure_ascii)

json.dump(data, f_output, ensure_ascii=ensure_ascii)
f_output.close()

def get_data(self):
"""Wrapper for getting data from input dict.
Expand Down

1 comment on commit f109746

@DarkZatarra
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that this coommit is needed in order to fix Abuseipdb

Please sign in to comment.