Internal Server Error Multiple Arguments Fed to Application

yjennykim
FREE

3 months ago

I'm facing an issue getting the application to deploy without an internal server error. My application is very simple and modified from the Flask tutorial. I'm able to run it locally flask --app enroute run and using gunicorn gunicorn --bind 0.0.0.0:8080 enroute:create_app

However when I deploy with railway, it fails with the following error

  File "/opt/venv/lib/python3.12/site-packages/gunicorn/workers/sync.py", line 134, in handle
  File "/opt/venv/lib/python3.12/site-packages/gunicorn/workers/sync.py", line 177, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: create_app() takes from 0 to 1 positional arguments but 2 were given

What arguments is Railway feeding into the entrypoint?

Supporting details:

Project structure

├── README.md
├── __pycache__
│   ├── __init__.cpython-313.pyc
│   └── app.cpython-313.pyc
├── enroute
│   ├── __init__.py
│   ├── __pycache__
│   ├── auth.py
│   ├── db.py
│   ├── flights.py
│   ├── schema.sql
│   ├── static
│   └── templates
├── instance
│   └── enroute.sqlite
├── main.py
├── nixpacks.toml
└── requirements.txt

main.py

import os
from enroute import create_app

application = create_app()

if __name__ == "__main__":
    application.run(debug=True, port=os.getenv("PORT", default=5000))

enroute/__init__.py

# most of this code is from the Flask tutorial
def create_app(test_config=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        # a default secret that should be overridden by instance config
        SECRET_KEY="dev",
        # store the database in the instance folder
        DATABASE=os.path.join(app.instance_path, "enroute.sqlite"),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile("config.py", silent=True)
    else:
        # load the test config if passed in
        app.config.update(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # register the database commands
    from . import db

    db.init_app(app)

    # apply the blueprints to the app
    from . import auth
    from . import flights

    app.register_blueprint(auth.bp)
    app.register_blueprint(flights.bp)
    app.add_url_rule("/", endpoint="flights")

    return app

Following the basic Railway example here: https://github.com/railwayapp-templates/flask/blob/main/main.py#L12

Following the basic Flask tutorial here: https://flask.palletsprojects.com/en/stable/quickstart/

Thank you.

Solved

2 Replies

3 months ago

Hello,

Your start command should be - gunicorn --bind 0.0.0.0:8080 main:application

Best,
Brody


Status changed to Awaiting User Response railway[bot] 3 months ago


yjennykim
FREE

3 months ago

Thank you so much!


Status changed to Awaiting Railway Response railway[bot] 3 months ago


Status changed to Solved yjennykim 3 months ago