While trying to retrieve data from the python api i created below, i get ‘Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)’ error line 3 of the js file. I tried restarting and going through the process again but that resulted in the same thing.
app.js
/*async function fetchdata(){*/
try {
const response = await fetch('http://127.0.0.1:5000/api/get_data');
const data = await response.json(); // Convert response to JSON
console.log('Data:', data);
// return data;
} catch (error) {
console.error('Error:', error);
}
/*}
fetchdata();*/
app.py
@app.route('/api/get_data', methods=['GET'])
def get_data():
form = loginForm()
print('hello')
data = {
"ownsPython": str(User.query.filter_by(username = form.username.data).first().javascriptOwner),
"ownsJava" : str(User.query.filter_by(username = form.username.data).first().pythonOwner),
"ownsPython" : str(User.query.filter_by(username = form.username.data).first().ownsJavascript)
}
return jsonify(data)