Flask允许分块数据还是使用其他库?

时间:2019-01-31 21:00:33

标签: python flask rasa-core

嗨,我正在研究一个使用以下代码教程的python rasa chatbot项目:https://github.com/RasaHQ/rasa_core/issues/119允许发布对rasa框架的调用。我遇到了一个问题,即如果post调用成块出现,python将无法接受。有没有办法通过Flask接受分块数据,或者您会建议使用其他Webhook库?预先谢谢你!

Python:

class SimpleWebBot(HttpInputComponent):
"""A simple web bot that listens on a url and responds."""

def blueprint(self, on_new_message):
    custom_webhook = Blueprint('custom_webhook', __name__)
    CORS(custom_webhook)

    @custom_webhook.route("/webhook", methods=['POST'])
    def receive():
        payload = request.json
        sender_id = payload.get("sender", None)
        text = payload.get("message", None)
        out = CollectingOutputChannel()
        on_new_message(UserMessage(text, out, sender_id))
        responses = [m for _, m in out.messages]
        return jsonify(responses)

1 个答案:

答案 0 :(得分:0)

在我看来,对输入通道的分块调用没有任何意义。 您要发送到Rasa Core输入通道的有效负载应该很小。通常,它们包括

  • 发件人ID
  • 一些授权标头
  • 发给机器人的用户消息

这应该是几千字节的大小,这使得分块请求的使用效率很低。