【问题标题】:Getting a 400 bad request error while testing测试时收到 400 错误请求错误
【发布时间】:2021-03-20 07:41:19
【问题描述】:

我正在我的 ecom 网站上为供应商制作注册表单,并且在执行发布请求时遇到了错误的请求错误。我试图找出导致此错误的原因,但一切似乎都很好。我使用了一个类似的模板,它工作正常,但我不知道这个有什么问题。看看我的代码,请帮我找出问题所在。

HTML 代码:

<div class="col">
    <form action="{{ url_for('Vendor_registration') }}" method="post" style="padding-top:1%;">
        <div class="form-group">
            <label for="first">First Name:</label>
            <input type="text" name="first_name" class="form-control" placeholder="For eg : Andrew" id="first" maxlength="15">
        </div>
        <div class="form-group">
            <label for="middle">Middle Name:</label>
            <input type="text" name="middle_name" class="form-control" placeholder="For eg : Jason" id="middle" maxlength="15">
        </div>
        <div class="form-group">
            <label for="last">Last Name:</label>
            <input type="text" name="last_name" class="form-control" placeholder="For eg : Sebastian" id="last" maxlength="15">
        </div>
        <div class="form-group">
            <label for="contact">Contact Number:</label>
                <input type="text" name="contact_no" class="form-control" placeholder="For eg : 0123456789" id="contact" maxlength="10">
        </div>
         <div class="form-group">
             <label for="email">Email address:</label>
             <input type="email" name="email" class="form-control" placeholder="For eg : abc@abc.com" id="email" maxlength="30">
         </div>
         <div class="form-group">
             <label for="pwd">Password:</label>
             <input type="password" name="password" class="form-control" placeholder="********" id="pwd" maxlength="15">
         </div>
         <div class="form-group">
             <label for="shop">Shop Name:</label>
             <input type="text" name="shop_name" class="form-control" placeholder="For eg : abc store" id="shop" maxlength="15">
         </div>
         <div class="form-group">
             <label for="certificate">Shop Certificate:</label>
             <input type="file" name="image" class="form-control-file border" id="certificate">
         </div>
         <div class="form-group">
             <label for="account">Bank Account number:</label>
             <input type="text" name="account_no" class="form-control" id="account" maxlength="20">
         </div>
         <div class="form-group">
             <label for="upi">UPI ID:</label>
             <input type="text" name="upi_id" class="form-control" id="upi" maxlength="15">
         </div>
         <button type="submit" class="btn btn-success btn-block">Submit</button>
     </form>
</div>

Python 代码:

@app.route("/vendor_register", methods=["GET","POST"])
def Vendor_registration():
    email=str(request.form.get("email"))
    first_name=str(request.form.get("first_name"))
    middle_name=str(request.form.get("middle_name"))
    last_name=str(request.form.get("last_name"))
    shop_name=str(request.form.get("shop_name"))
    phone_no=str(request.form.get("contact_no"))
    password=str(request.form.get("password"))
    account_no=str(request.form.get("account_no"))
    upi_id=str(request.form.get("upi_id"))
    shop_certificate=" "
    file=request.files["image"]
    return "done"

日志:

└─$ flask run
 * Serving Flask app "application.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production   deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [20/Mar/2021 03:13:46] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [20/Mar/2021 03:13:48] "POST /vendor_registration HTTP/1.1" 200  -
127.0.0.1 - - [20/Mar/2021 03:13:58] "POST /vendor_register HTTP/1.1" 400 -
^C   

【问题讨论】:

标签: html python-3.x flask


【解决方案1】:

我得到了答案。我实际上忘记在表单中提及 mime 类型是 ' enctype="multipart/form-data" ',因为还有一个图像。现在问题解决了。

【讨论】:

    【解决方案2】:

    您的网络服务器可能正在运行 mod_security 吗?

    【讨论】:

    • 不,@Calvin Ellis,我没有使用 mod_security 运行我的服务器。实际上我必须指定正确的 mimetype 来解决这个问题。感谢您提供时间和帮助。
    猜你喜欢
    • 1970-01-01
    • 2016-09-17
    • 2020-03-26
    • 1970-01-01
    • 2016-09-11
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多