Forums

"Applicazione Flask non si avvia - ModuleNotFoundError: flask_cors"

Subject: Flask Web App Not Starting - ModuleNotFoundError: flask_cors Hello PythonAnywhere team,

My web application at http://robertodigregoli.pythonanywhere.com/ is not starting.

The error log (/var/log/www/robertodigregoli.pythonanywhere.com.error.log) is not updating and only shows old messages from August 14, 2025, specifically: ModuleNotFoundError: No module named 'flask_cors'.

I have already tried the following steps:

Installed flask-cors using pip3.13 in the Bash console.

Verified and set my web app's Python version to 'Python 3.13' in the Web section.

Performed multiple reloads of my web app, waiting each time.

Despite these actions, the application does not start, and the error log remains static, which suggests a process-level issue. Could you please check my web application process and internal system logs to diagnose and resolve this problem?

Thank you in advance for your help.

Best regards, Roberto Di Gregoli

If the error log is not updating it can mean that the issue has been resolved -- is your web app crashing or showing errors?

Hello pafk,

Thank you for your reply.

Unfortunately, I have to confirm that the problem is not resolved. My web application (http://robertodigregoli.pythonanywhere.com/visualizza_dati.html) still shows the error 'Si è verificato un errore durante il recupero dei dati: Failed to fetch.' when I try to access it.

As I mentioned, the error log (/var/log/www/robertodigregoli.pythonanywhere.com.error.log) is not updating with current timestamps. It continues to show only the old errors from August 14, 2025 (ModuleNotFoundError: No module named 'flask_cors'). This leads me to believe that the web application is not even managing to start or log new errors.

I have tried reloading the app multiple times, and I have confirmed that the Python version is 3.13 and that flask-cors is installed for that version.

Could you please investigate this behavior further at the server process level, as the logs do not reflect the current startup attempts?

Thank you again for your help.

Best regards, Roberto Digregoli

The link you pasted (mind the http protocol) works fine. It happens only on https, and it looks like it's your code that is showing this error message. So you need to check your code and see what is producing that and maybe add more logging so you could see what is going on there.

Hello pafk,

Thank you for your continued assistance.

I have updated my server.py file as suggested, and it now has 226 lines, including the definition of the new /api/dati_anagrafica_2024 endpoint and the logic to read the CSV. I have also confirmed that pandas and openpyxl are installed for Python 3.13.

However, the problem persists:

When I access https://robertodigregoli.pythonanywhere.com/visualizza_dati_2024.html, the HTML page loads, but it shows the error 'Si è verificato un errore durante il recupero dei dati: Errore HTTP: 404 NOT FOUND.' for the API call.

The error log (/var/log/www/robertodigregoli.pythonanywhere.com.error.log) still only shows old errors from August 14, 2025 (ModuleNotFoundError: No module named 'flask_cors') and does not update with current timestamps after numerous web application reloads.

This indicates that the web application is not successfully starting with the updated server.py and is not logging new startup attempts.

Could you please perform a more in-depth check or a manual reset of my web application's environment? It seems the process is stuck and unable to load the new code.

Thank you again for your help.

Best regards, Roberto Digregoli

You do not have a view defined for "/" and that is why your web app returns a 404 for that path. Make sure that you have a view defined for "/" and then it will respond to a request for "/"

Hello glenn,

Thank you for your response.

You are correct that I do not have a view defined for the root path /, so a 404 for that path is expected. My apologies if that caused confusion.

However, the specific problem I'm experiencing is on my https://robertodigregoli.pythonanywhere.com/visualizza_dati_2024.html page. This page loads correctly, but the JavaScript on it attempts to fetch data from the API endpoint:

https://robertodigregoli.pythonanywhere.com/api/dati_anagrafica_2024

This API call then results in a "Failed to fetch: 404 NOT FOUND" error in the browser.

I have confirmed that my server.py file (which now has 226 lines) does define this specific endpoint (/api/dati_anagrafica_2024) and includes the load_data_from_csv_2024() function. I have also ensured pandas and openpyxl are installed for Python 3.13.

Furthermore, my error log (/var/log/www/robertodigregoli.pythonanywhere.com.error.log) still only shows old errors from August 14, 2025, and does not update with current timestamps even after multiple web app reloads. This suggests the server is not starting correctly with the updated code or is not logging new events.

Could you please check specifically why the /api/dati_anagrafica_2024 endpoint is returning a 404, despite being defined in server.py, and why my error log is not updating?

Thank you for your continued help.

Best regards, Roberto Digregoli

Could you check if the endpoint for /api/dati_anagrafica_2024 is not returning 404? You can have an endpoint which does return 404 in some cases.

Hello pafk,

Thank you for the suggestion.

My server.py code does indeed have logic to return a 404 if the data cannot be found or parsed from the CSV file. The specific code is:

def load_data_from_csv_2024(): try: df = pd.read_csv(CSV_FILE_2024, delimiter=',') # ... processing code ... except FileNotFoundError: print(f"Error: The CSV file '{CSV_FILE_2024}' not found.") return [] except Exception as e: print(f"Error during CSV loading or parsing: {e}") return []

@app.route('/api/dati_anagrafica_2024', methods=['GET']) def get_dati_anagrafica_2024(): try: data = load_data_from_csv_2024() if not data: return jsonify({'message': 'No data found in the CSV or parsing error'}), 404 return jsonify(data), 200 except Exception as e: return jsonify({'error': f'Error fetching data from CSV: {str(e)}'}), 500

Given that I am receiving the 404 error, it strongly suggests that the FileNotFoundError is being triggered because the anagrafica Arisgan 2024.xlsx - ANAGRAFICA 2024.csv file is either not in the /home/robertodigregoli/ directory or the file name is incorrect.

Could you please confirm if the file anagrafica Arisgan 2024.xlsx - ANAGRAFICA 2024.csv is present in my home directory?

Thank you again for your help.

Best regards, Roberto Digregoli

Hello pafk,

Thank you for your response.

I have followed all the steps:

I converted the .xlsx file to a .csv file.

I uploaded the .csv file to my home directory and confirmed its presence.

I deleted the original .xlsx file.

I reloaded the web application from the 'Web' tab.

Despite these steps, the web application still returns a "404 NOT FOUND" error for the /api/dati_anagrafica_2024 endpoint. The error log also remains outdated.

This leads me to believe the issue is not with the file itself, but with the PythonAnywhere server not correctly reloading the latest version of my server.py file, which is 226 lines long and correctly defines the endpoint.

Could you please manually trigger a fresh reload or a process restart for my application?

Thank you for your patience and assistance.

Best regards, Roberto Digregoli

What state is your file currently in? We can take a look, but we ask first.

Subject: Flask Web App Not Starting / 404 on New Endpoint - Error Log Not Updating Hello PythonAnywhere team,

My web application at https://robertodigregoli.pythonanywhere.com/ is experiencing issues.

Specifically, when I try to access https://robertodigregoli.pythonanywhere.com/visualizza_dati_2024.html, I receive an "HTTP: 404 NOT FOUND" error for the API call to /api/dati_anagrafica_2024. The frontend code is correctly pointing to this endpoint.

Crucially, the error log (/var/log/www/robertodigregoli.pythonanywhere.com.error.log) is not updating with current timestamps. It still shows old errors from August 14, 2025, specifically ModuleNotFoundError: No module named 'flask_cors', even after numerous web app reloads. This strongly suggests that the web application process is not starting with the updated server.py and is therefore unable to log any new errors or serve new endpoints.

I have already performed the following troubleshooting steps:

Confirmed pandas is installed in my virtual environment (as shown in my Bash console output).

Verified that the CSV file anagrafica Arisgan 2024.csv is correctly placed in the same directory as server.py.

Ensured my server.py includes the /api/dati_anagrafica_2024 endpoint.

Executed multiple "Reload" actions for my web app, waiting for the process to complete.

Cleared browser cache and cookies on multiple browsers.

Given that the error log is stagnant, I suspect there might be a stuck process or a deeper configuration issue preventing my web application from restarting correctly on your servers.

Could you please investigate this at the server process level to diagnose and resolve why my Flask app is not starting and logging new errors?

Thank you for your assistance.

Best regards, Roberto Digregoli

Hello fjl,

Thank you for your response.

Yes, please! You have my full permission to check my files directly. I would be very grateful if you could take a look.

The problem persists as described:

I'm getting an "HTTP: 404 NOT FOUND" error when accessing /api/dati_anagrafica_2024 from https://robertodigregoli.pythonanywhere.com/visualizza_dati_2024.html.

The crucial issue is that my error log (/var/log/www/robertodigregoli.pythonanywhere.com.error.log) is still not updating with current timestamps, showing errors from August 14, 2025. This suggests the application isn't even starting correctly.

My current server.py file is located at /home/robertodigregoli/server.py.

Thank you for your help!

Best regards, Roberto Digregoli

Have a look at get_dati_anagrafica_2024 view in your code, it returns 404 when there's no data (currently) in line 177:

return jsonify({'messaggio': 'Nessun dato trovato nel CSV o errore nel parsing'}), 404

So it's not an error, it's your code returning that.