如何在 python 中发送状态 200 应答 HTTPS POST

1 python https http-status-code-200

我正在使用 Flask 创建一个应用程序,该应用程序通过 HTTPS POST 从服务器接收一些数据并处理其数据。一旦我收到来自服务器的消息,我需要发送“status = 200”,以便服务器知道我收到了信息,并停止重新向我发送信息。

我必须发送 HTTPS GET 吗?这并不是真正的获取,因为我唯一需要的就是通知服务器我收到了消息......

我怎样才能在Python中做到这一点?我需要在处理收到的数据但不返回后执行此操作。

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
Run Code Online (Sandbox Code Playgroud)

谢谢!

fin*_*ngu 5

如果您想确定响应代码,您可以发送空响应并仅指定响应代码,如下所示

return '', 200
Run Code Online (Sandbox Code Playgroud)

完整的答案可以在 Flask 中的 Return HTTP status code 201中找到

更新问题的更新:

你可以使用 aThread来实现这一点。

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
Run Code Online (Sandbox Code Playgroud)