This is my Flask code:
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)
I run this HTTP Post (from the same machine):
import requests
import json
dump= '{"on":"true"}'
r = requests.post('http://127.0.0.1:5000', dump)
And receive this error:
[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
Any ideas on why this is occuring? From reading online at first I thought it was because I didn't have an else in case of it being a GET, but I can't understand now.