python - Flask - TypeError:视图函数没有返回有效响应
问题描述
Flaskredirect
在 localhost 上运行良好,但在部署到Vercel后抛出错误
我的代码 -
try:
return redirect(str(urlDictionary[path]), code=302)
except Exception as e:
return e
它返回的异常 -
TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a KeyError
错误 -
[ERROR] 2021-05-24T07:22:02.390Z 6f2998c4-473a-4abc-8340-20792c0bd008 Exception on /C8F14 [GET]Traceback (most recent call last): File "/var/task/flask/app.py", line 2070, in wsgi_app response = self.full_dispatch_request() File "/var/task/flask/app.py", line 1515, in full_dispatch_request rv = self.handle_user_exception(e) File "/var/task/flask/app.py", line 1513, in full_dispatch_request rv = self.dispatch_request() File "/var/task/flask/app.py", line 1499, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/var/task/app.py", line 36, in RedirectShort return redirect(str(urlDictionary[path]), code=302)KeyError: 'C8F14'127.0.0.1 - - [24/May/2021 07:22:02] "GET /C8F14 HTTP/1.1" 500 290
解决方案
推荐阅读
- linux - sys_write 在程序集 [msg] 或 msg 中?
- javascript - 为什么我的 JavaScript 分页代码显示的条目数比当前页面上的条目数多?
- c# - 如何使用 build.binaries 目录变量
- asp.net-mvc - 检查模型的真实值
- python - 错误:字段大于字段限制 (131072)
- dji-sdk - UpdateJoystickValue 在 Windows-SDK 中不起作用
- ios - UITableView - 标题高度更改后重新定位单元格
- java - 没有找到 messages_XX.properties
- ruby-on-rails - 使用 Prawn 和 Carrierwave 上传 PDF 而不将文件保存在磁盘上
- c# - 如何在 C# 中编辑匿名动态列表