From 3c1154923fe1bf1e0c1521cd38d1681a6a39e98d Mon Sep 17 00:00:00 2001 From: clowwindy Date: Mon, 10 Aug 2015 00:05:22 +0800 Subject: [PATCH] fix json unicode issue in manager --- shadowsocks/manager.py | 2 +- shadowsocks/shell.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/shadowsocks/manager.py b/shadowsocks/manager.py index d93eacc..e125ef4 100644 --- a/shadowsocks/manager.py +++ b/shadowsocks/manager.py @@ -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') diff --git a/shadowsocks/shell.py b/shadowsocks/shell.py index bdba6c6..c91fc22 100644 --- a/shadowsocks/shell.py +++ b/shadowsocks/shell.py @@ -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)