I am using Flask to create an application that receives some data from a server with an HTTPS POST and process its data. Once i receive the message from the server I need to send a "status = 200" so the server will know that i got the info, and stop re-sending me the information.
Do i have to send a HTTPS GET? It is not really a get as the only thing i need is to notify the server i got the message...
How can i do it in python? I need to do it after processing the data i receive but without return.
app = Flask(__name__)
@app.route('/webhook', methods=['POST','GET'])``
def webhook():
req = request.form
xml = req['data']
#HOW DO I SEND A CODE 200 NOW???
info = ET.fromstring(xml)
print info[0].text
print info[1].text
print info[2].text
print info[3].text
Thanks!
If you want to be sure about the response code, you can send an empty response and only specify the response code like so
return '', 200
The complete answer can be found at Return HTTP status code 201 in flask
UPDATE FOR UPDATED QUESTION:
You could use a Thread
for that.
import threading
app = Flask(__name__)
@app.route('/webhook', methods=['POST','GET'])``
def worker(xml):
info = ET.fromstring(xml)
print info[0].text
print info[1].text
print info[2].text
print info[3].text
return
def webhook():
req = request.form
xml = req['data']
# This executes in background
t = threading.Thread(target=worker, args=(xml,))
t.start()
# So that you can return before worker is done
return '', 200