fix: correct JSON serialization in exec_code method

This commit is contained in:
CaptainB 2025-09-04 18:10:11 +08:00
parent dc2b83b8a3
commit 452188e7bb

View File

@ -40,7 +40,7 @@ class ToolExecutor:
def exec_code(self, code_str, keywords):
self.validate_banned_keywords(code_str)
_id = str(uuid.uuid7())
success = '{"code":200,"msg":"成功","data":json.dumps(exec_result, default=str)}'
success = '{"code":200,"msg":"成功","data":exec_result}'
err = '{"code":500,"msg":str(e),"data":None}'
result_path = f'{self.sandbox_path}/result/{_id}.result'
python_paths = CONFIG.get_sandbox_python_package_paths().split(',')
@ -65,7 +65,7 @@ try:
globals_v[local] = locals_v[local]
exec_result=f(**keywords)
with open({result_path!a}, 'w') as file:
file.write(json.dumps({success}))
file.write(json.dumps({success}, default=str))
except Exception as e:
with open({result_path!a}, 'w') as file:
file.write(json.dumps({err}))