Show
错误类型[POST]>400 Bad Request: The browser (or proxy) sent a request that this server could not understand. 400 (错误请求) 服务器不理解请求的语法。 使用场景flask后台报400错误。400错误表示 由于语法格式有误,服务器无法理解此请求。 更正总结:json数据不能用表单接收, 表单最好也不要接收json数据Flask 中接收与发送表单方式from flask import Flask,render_template,request @app.route('/login',methods=['GET','POST']) def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] print username,password return render_template('login.html',method=request.method)Flask 中接收与发送json 方式详解(转)https://blog.csdn.net/gymaisyl/article/details/86629874 1、利用flask的request.form.get()方法接收 from flask import Flask from flask import jsonify from flask import request import json @app.route("/login", methods=['POST']) def login(): data_ = request.form.get('data') data = json.loads(data) username = data['username'] password = data['password'] return jsonify({"login": Login.login(username, password)}) # 返回布尔值2、 利用flask的request.get_data()方法接收 from flask import Flask from flask import jsonify from flask import request import json @app.route("/flask/login", methods=['POST']) def login(): data = request.get_data() data = json.loads(data) username = data['username'] password = data['password'] return jsonify({"login": Login.login(username, password)}) # 返回布尔值3、利用flask的request.get_json()方法接收 from flask import Flask from flask import jsonify from flask import request @app.route("/flask/login", methods=['POST']) def login(): data = request.get_json() username = data['username'] password = data['password'] return jsonify({"login": Login.login(username, password)}) # 返回布尔值
The 400 Bad Request error is an HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it. The 400 Bad Request error is often caused by entering or pasting the wrong URL in the address window but there are some other relatively common causes as well. 400 Bad Request errors, like all errors of this type, could be seen in any operating system and in any browser. 400 Bad Request Errors400 Bad Request errors appear differently on different websites, so you may see something from the short list below instead of just 400 or another simple variant like that:
The 400 Bad Request error displays inside the internet web browser window, just as web pages do. How to Fix the 400 Bad Request Error
More Ways You Might See a 400 ErrorIn Internet Explorer, The webpage cannot be found message indicates a 400 Bad Request error. The IE title bar will say HTTP 400 Bad Request or something very similar to that. Windows Update can also report HTTP 400 errors but they display as error code 0x80244016 or with the message WU_E_PT_HTTP_STATUS_BAD_REQUEST. A 400 error that's reported for a link within a Microsoft Office application will often appear as a The remote server returned an error: (400) Bad Request. message within a small pop-up window. Web servers running Microsoft IIS often give more specific information about the cause of a 400 Bad Request error by suffixing a number after the 400, as in HTTP Error 400.1 - Bad Request, which means Invalid Destination Header. Here's a complete list:
Errors Like 400 Bad RequestA number of other browser errors are also client-side errors and so are at least somewhat related to the 400 Bad Request error. Some include 401 Unauthorized, 403 Forbidden, 404 Not Found, and 408 Request Timeout. Server-side HTTP status codes also exist and always start with 5 instead of 4. You can see all of them in our HTTP Status Code Errors list. FAQ
Thanks for letting us know! How do you fix your browser sent a request that this server could not understand?This issue can be caused by corrupted cookies. Clear the Cache and remove the Cookies for websites that cause problems via the "3-bar" Firefox menu button (Options/Preferences). If clearing cookies didn't help then it is possible that the cookies.
What does bad request your browser sent a request that this server could not understand size of a request header field exceeds server limit?This issue can be caused by corrupted cookies. Clear the cache and remove the cookies from websites that cause problems via the "3-bar" Firefox menu button (Options/Preferences). "Clear the cache: Options/Preferences -> Privacy & Security -> Cached Web Content: "Clear Now"
What is request Get_json?Request. get_json (force=False, silent=False, cache=True)[source] Parses the incoming JSON request data and returns it. By default this function will return None if the mimetype is not application/json but this can be overridden by the force parameter.
How do you request a body in flask?Parse it in Flask with request. get_json() .. form['name'] : use indexing if you know the key exists.. form. get('name') : use get if the key might not exist.. form. getlist('name') : use getlist if the key is sent multiple times and you want a list of values. get only returns the first value.. |