通过REST API执行OML4Py嵌入脚本时为何收到JSON格式错误?
OML4Py REST API执行嵌入脚本时JSON格式错误修复
问题场景
通过REST API执行OML4Py嵌入脚本时触发JSON格式错误,执行的curl命令如下:
$ curl -i -X POST --header "Authorization: Bearer ${token}" --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"graphicsFlag":true, "service":"MEDIUM"}' "/oml/api/py-scripts/v1/do-eval/myscript"
返回的错误信息:
{"errorMessage":"Output malformed JSON. This could be caused by explicitly calling print() in the executed Python script. Remove print() call from the script should solve the issue.","errorCode":1026}
解决方法
根据错误提示,问题根源是执行的Python脚本中存在显式调用print()函数的情况,这些print输出会干扰API返回的JSON结构,导致格式异常。直接移除脚本中所有的print()调用即可解决该问题。
内容的提问来源于stack exchange,提问作者Philip Cannata
相关产品推荐
相关产品推荐

