首页 > 解决方案 > 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

标签: pythonflasktypeerrorvercel

解决方案


推荐阅读