Answer the question
In order to leave comments, you need to log in
How to fix JSON.parse error?
Good afternoon, I encountered such a problem:
When sending login / password data to the server, I get an error:
JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
let response = await fetch(URL_SERVER_LINK + "/login_client", {
method: "POST",
mode: "no-cors",
credentials: "include",
headers: {
"Access-Control-Allow-Origin": "*",
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
Username: login,
Password: password,
}),
});
@application.route('/login_client', methods=['POST'])
def login_client():
auth = request.authorization
username = request.json.get('username', None)
password = request.json.get('password', None)
if not auth or not auth.username or not auth.password:
return make_response('Could not verify', 401, {'WWW-Authenticate' : 'Basic realm="Login required!"'})
client = Client.query.filter_by(name=auth.username).first()
if not client:
return make_response('Could not verify', 401, {'WWW-Authenticate' : 'Basic realm="Login required!"'})
if check_password_hash(client.password, auth.password):
return jsonify({"token": create_access_token(identity=auth.username)})
Answer the question
In order to leave comments, you need to log in
This thing in the request looks, in my opinion, wrong:
{
Username: login,
Password: password,
}
{
'Username': login,
'Password': password,
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question