這是我的瓶代碼:的Python瓶ValueError異常:查看功能並沒有返回響應
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def signal():
if request.method == 'POST':
content = request.get_json()
return content
else:
return 'Hello, world!'
if __name__ == '__main__':
app.run(debug=True)
我運行這個HTTP後(從同一臺機器):
import requests
import json
dump= '{"on":"true"}'
r = requests.post('http://127.0.0.1:5000', dump)
而且收到此錯誤:
[2017-03-04 14:18:35,250] ERROR in app: Exception on/[POST]
Traceback (most recent call last):
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\flask\app.py", line 1615, in full_dispatch_request
return self.finalize_request(rv)
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\flask\app.py", line 1630, in finalize_request
response = self.make_response(rv)
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\flask\app.py", line 1725, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response
任何想法,爲什麼發生這種情況?從一開始我就在網上閱讀,我認爲這是因爲我沒有其他的東西,因爲它是一個GET,但我現在無法理解。
縮進是錯誤的,還是僅僅來自複製/粘貼? – Vallentin
這可能是複製粘貼,但你究竟意味着什麼?在IF下? –