is python 2 happy now

This commit is contained in:
thomwolf
2019-04-17 14:48:34 +02:00
parent 265550ec34
commit 23d4554ec0

View File

@@ -242,7 +242,10 @@ def get_from_cache(url, cache_dir=None):
meta = {'url': url, 'etag': etag} meta = {'url': url, 'etag': etag}
meta_path = cache_path + '.json' meta_path = cache_path + '.json'
with open(meta_path, 'w') as meta_file: with open(meta_path, 'w') as meta_file:
meta_file.write(json.dumps(meta, indent=4)) output_string = json.dumps(meta)
if sys.version_info[0] == 2 and isinstance(output_string, str):
output_string = unicode(output_string, 'utf-8') # The beauty of python 2
meta_file.write(output_string)
logger.info("removing temp file %s", temp_file.name) logger.info("removing temp file %s", temp_file.name)