sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.
https://sanic.dev
MIT License
18.08k stars 1.55k forks source link

form data parse fail #1982

Closed lswjkllc closed 3 years ago

lswjkllc commented 3 years ago

Describe the bug By viewing the log, request body can look three fields("name","data_set_tyep","info") in handler function, but, when I get request data by request.form, just get two fields data("data_set_tyep","info")

Code snippet

@app.route("/excel/input", methods=["POST"])
def handler(request):
        logger.info(f"excel_input request body: { request.body }")
        # get file
        excel_file = request.files.get("excel_file")
        # get form data
        # input_param = self.get_request_form(request)
        input_param = request.form
        logger.info(f"excel input form data: { input_param }")
        ...

Expected behavior ...

Environment (please complete the following information):

Additional context ...

ahopkins commented 3 years ago

I am assuming you got this working fine?

from sanic import Sanic
from sanic.log import logger
from sanic.response import text

app = Sanic("__BASE__")

@app.post("/")
async def get1(request):
    logger.info(f"excel_input request body: { request.body }")
    input_param = request.form
    logger.info(f"excel input form data: { input_param }")
    return text("Done.")

if __name__ == "__main__":
    app.run(access_log=False, debug=True, port=9999)
[2020-12-24 19:57:31 +0200] [100744] [INFO] Goin' Fast @ http://127.0.0.1:9999
[2020-12-24 19:57:31 +0200] [100744] [INFO] Starting worker [100744]
[2020-12-24 19:57:33 +0200] [100744] [INFO] excel_input request body: b'--X-INSOMNIA-BOUNDARY\r\nContent-Disposition: form-data; name="name"\r\n\r\nadam\r\n--X-INSOMNIA-BOUNDARY\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n--X-INSOMNIA-BOUNDARY\r\nContent-Disposition: form-data; name="fizz"\r\n\r\nbuzz\r\n--X-INSOMNIA-BOUNDARY--\r\n'
[2020-12-24 19:57:33 +0200] [100744] [INFO] excel input form data: {'name': ['adam'], 'foo': ['bar'], 'fizz': ['buzz']}
[2020-12-24 19:57:38 +0200] [100744] [DEBUG] KeepAlive Timeout. Closing connection.