最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

[已解决]Flask运行出错:ValueError: View function did not return a response

Flask crifan 4173浏览 0评论

Flask的代码:

@app.route(‘/sipevents’, methods=[‘GET’, ‘POST’])
def sipevents():
                sendArticelResp = wechat.send_article_message(sourceUser.openid, showEventArticleDict)
                gLog.debug("sendArticelResp=%s", sendArticelResp)
                return

运行出错:

[2016-08-31 19:44:09 +0000] [981] [ERROR] Error handling request /sipevents?signature=9c1e6b9683a62cd0989d5dbfb4313c8e3a041a48&timestamp=1472643849&nonce=588430275&openid=oswjmv4X0cCXcfkIwjoDfCkeTVVY
Traceback (most recent call last):
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/flask/app.py", line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/flask/app.py", line 1642, in full_dispatch_request
    response = self.make_response(rv)
  File "/root/Envs/SIPEvents/lib/python2.7/site-packages/flask/app.py", line 1731, in make_response
    raise ValueError(‘View function did not return a response’)
ValueError: View function did not return a response

看起来很明显:

Flask中没有返回response

-》

但是此处:

故意没有返回微信公众号的内容

-》因为前面已经返回过了对应的article文章内容了

对应的公众号中可以显示了:

文章下面的:

该公众号暂时无法提供服务,请稍后再试

就是由于上述错误,而无法正常返回,微信才显示错误的。

Flask ValueError: View function did not return a response

python – Flask Value error view function did not return a response – Stack Overflow

python – Flask view return error "View function did not return a response" – Stack Overflow

python – View function did not return a response – Stack Overflow

ValueError: View function did not return a response

在 Flask 里产生流式响应

浅入浅出Flask框架:获取URL参数 | 樂天笔记

ValueError: View function did not return a response · Issue #580 · benoitc/gunicorn

Question on Flask

Flask: View function did not return a response for js file – 墨迹技术问答

然后就是:

[已解决]如何给微信公众号服务器回复空内容

[总结]

Flask中,正常的话,确保返回有response回复,就可以避免:

ValueError: View function did not return a response

的错误了,而此处,确保有调用make_response即可。

比如:

return make_response("")

转载请注明:在路上 » [已解决]Flask运行出错:ValueError: View function did not return a response

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
65 queries in 0.118 seconds, using 18.90MB memory