Skip to content

Commit 3c11549

Browse files
author
clowwindy
committed
fix json unicode issue in manager
1 parent c5dd081 commit 3c11549

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

shadowsocks/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def run_server():
258258
data = common.to_str(data)
259259
assert data.startswith('stat: ')
260260
data = data.split('stat:')[1]
261-
stats = json.loads(data)
261+
stats = shell.parse_json_in_str(data)
262262
assert '7001' in stats
263263
logging.info('TCP statistics test passed')
264264

shadowsocks/shell.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ def get_config(is_local):
148148
logging.info('loading config from %s' % config_path)
149149
with open(config_path, 'rb') as f:
150150
try:
151-
config = json.loads(f.read().decode('utf8'),
152-
object_hook=_decode_dict)
151+
config = parse_json_in_str(f.read().decode('utf8'))
153152
except ValueError as e:
154153
logging.error('found an error in config.json: %s',
155154
e.message)
@@ -359,3 +358,8 @@ def _decode_dict(data):
359358
value = _decode_dict(value)
360359
rv[key] = value
361360
return rv
361+
362+
363+
def parse_json_in_str(data):
364+
# parse json and convert everything from unicode to str
365+
return json.loads(data, object_hook=_decode_dict)

0 commit comments

Comments
 (0)