Forums

restAPI - POST http://127.0.0.1:5000/login net::ERR_CONNECTION_REFUSED

HI,

I have a restAPI which performs simple CRUD operations on a SQL database. I have the database up and running and the CSS/HTML page linking working for the web interface put I keep getting the following error when trying to use the website to make these CRUD operations for example logging in or registering a user (http://g00398279.pythonanywhere.com/login.html/ )

      POST http://127.0.0.1:5000/login net::ERR_CONNECTION_REFUSED  jquery.min.js:2

I can't figure out where I am going wrong, if I run flask on my local machine it works perfectly.

I am getting the below in my error log , the server file is names as flask_app

2022-12-24 16:11:15,088: Error running WSGI application
2022-12-24 16:11:15,088: ModuleNotFoundError: No module named 'flask_app'
2022-12-24 16:11:15,088:   File "/var/www/g00398279_pythonanywhere_com_wsgi.py", line 16, in <module >
2022-12-24 16:11:15,089:     from flask_app import app as application  # noqa

Any help is greatly appreciated

It looks like you're making a POST request to port 5000 on the machine where that particular bit of code is running. If you're getting that error in the JavaScript console for your website, the problem is that your JS code is trying to make a request to the machine where the browser is running rather than to the server that served up the page.

Thank you so much, I have it working now.

Thank you and Happy Christmas

Excellent, glad we could help! A very happy New Year to you :-)