POSTing to a flask app

Hi, I have a very simple flask app:
python
from flask import Flask, jsonify, request
from waitress import serve
import os

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def index():
print(request)
return jsonify({"Hello from Flask!"})

if __name__ == '__main__':
serve(app, host='0.0.0.0', port=os.getenv("PORT"))
python
from flask import Flask, jsonify, request
from waitress import serve
import os

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def index():
print(request)
return jsonify({"Hello from Flask!"})

if __name__ == '__main__':
serve(app, host='0.0.0.0', port=os.getenv("PORT"))
When I try to POST to my endpoint in postman I get this in my log:
<Request 'MY_URL'; [GET]>
<Request 'MY_URL'; [GET]>
It is a GET request? This I think has been my problem when I try to run request.get_json() as there is nothing in the body as it is a GET? My question is, how can I fix this to send/receive POST requests properly (it works locally). Thanks :)
Solution:
your problem is that you arent requesting over https
Jump to solution
8 Replies
Percy
Percy2y ago
Project ID: N/A
Brody
Brody2y ago
do you have a procfile?
cheesy_pete
cheesy_pete2y ago
No
Brody
Brody2y ago
okay i see you are using waitress, no need for gunicorn
Solution
Brody
Brody2y ago
your problem is that you arent requesting over https
cheesy_pete
cheesy_pete2y ago
Wow, thank you that has solved it
MantisInABox
MantisInABox2y ago
Also, if you are doing GET and POST on the same endpoint, you should probably use a conditional on the request to see if it’s a post, then do your logic inside the conditional, and then provide your get logic outside of the conditional.
if request.method(“POST”):
<logic here>
return redirect()


<get logic>
return render_template()
if request.method(“POST”):
<logic here>
return redirect()


<get logic>
return render_template()
Just sayin
Brody
Brody2y ago
nerd
Want results from more Discord servers?
Add your server