fix json unicode issue in manager

This commit is contained in:
clowwindy 2015-08-10 00:05:22 +08:00
parent c5dd081216
commit 3c1154923f
2 changed files with 7 additions and 3 deletions

View file

@ -258,7 +258,7 @@ def test():
data = common.to_str(data)
assert data.startswith('stat: ')
data = data.split('stat:')[1]
stats = json.loads(data)
stats = shell.parse_json_in_str(data)
assert '7001' in stats
logging.info('TCP statistics test passed')

View file

@ -148,8 +148,7 @@ def get_config(is_local):
logging.info('loading config from %s' % config_path)
with open(config_path, 'rb') as f:
try:
config = json.loads(f.read().decode('utf8'),
object_hook=_decode_dict)
config = parse_json_in_str(f.read().decode('utf8'))
except ValueError as e:
logging.error('found an error in config.json: %s',
e.message)
@ -359,3 +358,8 @@ def _decode_dict(data):
value = _decode_dict(value)
rv[key] = value
return rv
def parse_json_in_str(data):
# parse json and convert everything from unicode to str
return json.loads(data, object_hook=_decode_dict)