'400 Bad request error, it is saying bad syntax for the curly brace - Flask Postman
I have been running through this code and I do not see where the issue is. This is the json I am submitting via Postman:
{
"username" : "John1",
"password" : "password",
"name" : "John Doe",
"email" : "[email protected]"
}
I have also used the brackets as well like so:
[
{
"username" : "chase1",
"password" : "Chasecoding1991",
"name" : "Chase Quinn",
"email" : "[email protected]"
}
]
It has the same issue either way, except with the brackets it shows the bracket as incorrect.
This is my routes code:
@cross_origin()
@auth_bp.route('/', methods=['GET', 'POST', 'PATCH', 'DELETE'])
def auth():
if request.method == 'GET':
return 'GET REQUEST received'
elif request.method == 'POST':
try:
data = request.get_json()
hashed_password = generate_password_hash(data['password'], method='sha256')
user = authModel(userid = str(uuid.uuid4()), name=data['name'], username = data['username'], password=hashed_password, email=data['email'])
db.session.add(user)
db.session.commit()
return 'successful'
except:
return jsonify({'status': '500'})
elif request.method == 'PATCH':
return 'PATCH REQUEST received'
elif request.method == 'DELETE':
return 'DELETE REQUEST received'
I am submitting the POST request via Postman using JSON as the body in the settings. There have been no headers set up as of yet on either side. I have no JWT set up as of yet either. I have also tried this with both http and https within Postman.
If anyone has any ideas please let me know!
The entire error excerpt is as follows:
127.0.0.1 - - [31/Mar/2022 08:36:02] "POST /auth HTTP/1.1" 308 -
127.0.0.1 - - [31/Mar/2022 08:36:02] code 400, message Bad request syntax ('{')
127.0.0.1 - - [31/Mar/2022 08:36:02] "None /auth HTTP/0.9" HTTPStatus.BAD_REQUEST -
Solution 1:[1]
I changed the url in postman to:
http://localhost:5000/auth/
the real error was the 308 redirect. It showed that the URL was not there. Once I did that the program worked flawlessly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chase Quinn |
