Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Server Error at Root Route / #2

Open
ericBlack1 opened this issue Nov 28, 2024 · 0 comments
Open

Internal Server Error at Root Route / #2

ericBlack1 opened this issue Nov 28, 2024 · 0 comments
Assignees

Comments

@ericBlack1
Copy link
Owner

Description:
Accessing the root route / triggers an internal server error (HTTP 500) due to an intentional exception in the code.

Steps to Reproduce:

  1. Run the Flask application using the provided code snippet.
  2. Open a web browser and navigate to http://127.0.0.1:5000/.
  3. Observe the error message and stack trace in the browser or console.

Expected Behavior:
The root route / should display the message "Welcome to your first Flask application!" or handle the exception gracefully.

Actual Behavior:
An internal server error (HTTP 500) occurs, with the following error message:

Internal Server Error: /  
Traceback (most recent call last):  
  File "<file_path>", line <line_number>, in home  
    raise Exception("Internal server error.")  
Exception: Internal server error.  

Code Snippet:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    raise Exception("Internal server error.")
    return "Welcome to your first Flask application!"

if __name__ == '__main__':
    app.run(debug=True)

Development Environment:

  • OS: Ubuntu 24.04.
  • Python Version: 3.12.3
  • Flask Version: 3.0.3

Suggested Fix:
Handle the exception gracefully or remove the exception to ensure the route works as expected. Example fix:

@app.route('/')
def home():
    try:
        # Logic here
        return "Welcome to your first Flask application!"
    except Exception as e:
        return f"An error occurred: {str(e)}", 500

Let me know if further details are needed!

Ericblak added a commit that referenced this issue Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants