问题描述
因此,我具有以下视图功能(我正在尝试在Open APIV3项目上工作):
def my_view_func_in_python():
return_dict = {"status": False,"stdout": None,"stderr": None}
try:
payload = connexion.request.get_json()
json_data = payload["json"]
fileName = payload["fileName"]
text_lines = []
for line in json_data["res"][0]["lines"]:
text_lines.append(line["text"])
text = " ".join(text_lines)
os.remove("./assets/request.jpg")
return_dict.update([
("status",True)
])
except BaseException as ex:
return_dict.update([
("stderr",ex)
])
return return_dict
现在由于某种原因,如果我通过挥舞给出一个空的json字段值,则代码会在具有for循环for line in json_data["res"][0]["lines"]
的行中中断。但是,如果它中断了,它应该进入例外行并和平返回return_dict。但是它给我的回报是挥舞着500错误。
SWAGGER输出:
{
"detail": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.","status": 500,"title": "Internal Server Error","type": "about:blank"
}
,在我托管应用程序的后端发生什么错误?
TypeError: Object of type 'KeyError' is not JSON serializable
我已经尝试了很多地方,开放的apiv3规范,swagger文档和connexion文档。我不能只捕捉到此错误!我该怎么办?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)