添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

今天使用python实现Flask的restful接口,然后调用的时候报错:

ValueError: View function did not return a response

代码如下:

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])
def receive():
      param = request.json
      print(param)

报错的原因是 Flask 的 Restful 接口是必须有返回值的。

因此修改代码添加返回值:

新增:return xxxx

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])
def receive():
        if not request.json:
            return jsonify({'code': -1, 'message': 'request is not json'})
        param = request.json
        return jsonify({'code': 0, 'status': 'running'})
    except Exception as e:
        print(e)
        return jsonify({'code': -1, 'error_message':e})
                    今天使用python实现Flask的restful接口,然后调用的时候报错:ValueError: View function did not return a response代码如下:@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])def receive():   param = request.json...
				
新手在学 flask 开发 T.T ,看到《 python web 开发》第十章的用户资料, 在搞 管理员级别的资料编辑器 那里出问题了, 视图函数抛出异常,不能返回响应 。百度,谷歌, sof 无果。找好久了没解决,心塞 所以来寻求帮助,谢谢能提供帮助的人检查过好几遍了,views.py,forms.py,模板都没发现问题 折腾了一晚上都没搞定,T.T 简直要哭了 解决过程:后来求助于网络社区
Solution: 参考stackoverflow给出的解决方案:https://stackoverflow.com/questions/65085956/pycharm-venv-failed-no-such-option-build-dir 确定自己pycharm里面python解释器的路径: 在cmd里面输入:自己解释器的路径 + -m pip install pip==20.2.4 (其中可能会有网络问题提示Retry,要多尝试几次) 这里做法的主要原因是:pycharm依赖于 –build-dir来安装包,但是这在最新版的pip中被移除了,所以解决办法 Traceback (most recent call last): File “D:/flaskProject/test.py”, line 35, in test pool.apply(self.out, args=(i,)) File “Python37-32\lib\multiprocessing\pool.py”, line 261, in apply return self.apply_async(func, args, kwds).get() File “\lib\multiprocessing\pool.py”, line 657, in get raise se
app.route和app.add_url_ruleapp.add_url_rule 这个方法是用来添加url与视图函数的映射。如果没有填写endpoint那么会默认使用view_func的名字来作为endpoint。 因此在使用url_for的时候,就要看在映射的时候有没有传递endpoint参数,如果传递了,那么就使用endpoint指定的字符串。
报错信息简略版:ValueError: View function did not return a response视图函数没有return一个响应。报错信息完整版:(venv_flask_henry) henry@henry-virtual-machine:~/dev/flask_henry$ python manage.py runserver --host 0.0.0.0 /home/hen
记一次flask项目开发中遇到的无脑问题。 TypeError: The view function did not return a valid response. The function either returned None #错误的原因是,代码中缺少return @app.route('/history_ocr/', methods=['GET', 'POST']) def history_ocr(): if request.method == 'GET': result
网上查了很多资料,都没解决这个问题,方法已经有return了,但是还是报错TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement. 后来才发现,我另外一个蓝图里面有个同名的路径,该同名路径无返回值。所以,在出现这种情况下,也要检查一下是否其他蓝图里有同名的路径
1. sqlite3.OperationalError: near "create": syntax error drop table if exists entries; create table entries ( id integer primary key autoincrem...
TypeError: The view function for ‘uploadImg’ did not return a valid response. The function either returned None or ended without a return statement. 解决方法: ①给函数写返回值(return一个值) ②看其他同名函数是否也return ③看看是不是代码少写了method 具体原博客添加链接描述 可能是前端没写也可能是后端没写 ④函数只有在if的时候有返回值,但
    @setupmethod     def before_request(self, f):         """Registers a function to run before each request."""         self.before_request_funcs.setdefault(None, []).append(f)
这个错误通常是由于 OpenSSL 版本过低引起的。您可以尝试升级 OpenSSL 版本或使用较新的 Python 版本解决此问题。您也可以尝试使用以下命令安装 Flask: pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org flask 该命令将信任所有主机并强制安装 Flask
Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfi 92926