Forums

Trouble with GET/ POST requests

Hi, I have a webapp running on Flask backend. I have the JS files and functions. The entire website runs fine on my local machine. The site even compiles on PythonAnywhere, but I get a set of errors at each request I make -

For eg - I have a button which loads the structure of a protein when clicked, this works fine on my local machine. But on PythonAnywhere, I get the following error - POST https://drugprotai.pythonanywhere.com/fetch_pdb 404 (NOT FOUND) script.js:153 Error fetching PDB file: SyntaxError: Unexpected token '<', "<!doctype "... is not valid JSON

My js function is -

fetch('/fetch_pdb', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ uniprot_id: uniprotId }) }) .then(response => response.json()) .then(data => { ....

and the corresponding call to the Flask app is -

@app.route('/fetch_pdb', methods=['POST']) def fetch_and_display_structure(): data = request.json uniprot_id = data.get('uniprot_id') .....

Check in your browser dev tools what url do you request there and if it matches your expectations.

This is the requested url - https://drugprotai.pythonanywhere.com/fetch_pdb

My js function is -

fetch('/fetch_pdb', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ uniprot_id: uniprotId }) }) .then(response => response.json()) .then(data => { ....

and the corresponding call to the Flask app is -

@app.route('/fetch_pdb', methods=['POST']) def fetch_and_display_structure(): data = request.json uniprot_id = data.get('uniprot_id') .....

The response you see (404) suggests that you are not hitting the url you expect to hit or that the endpoint is not working as you would expect. Do you see any 404 in the access log for /fetch_pdb?