0

I'm trying to run a Flask app into Google Cloud RUn using gunicorn, but i'm getting this error when i try to access the '/' page in Cloud Run (but it's working well in localhost). How can I fix this?

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1453, in dispatch_request
    self.raise_routing_exception(req)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1436, in raise_routing_exception
    raise request.routing_exception
  File "/usr/local/lib/python3.7/site-packages/flask/ctx.py", line 286, in match_request
    self.url_adapter.match(return_rule=True)
  File "/usr/local/lib/python3.7/site-packages/werkzeug/routing.py", line 1581, in match
    raise NotFound()
werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again. 

This is my app.py file

...


def create_app(settings_override=None):
    """
    Create a Flask application using the app factory pattern.

    :param settings_override: Override settings
    :return: Flask app
    """
    app = Flask(__name__, instance_relative_config=True)

    app.config.from_object("config.settings")
    app.config.from_pyfile("settings.py", silent=True)

    if settings_override:
        app.config.update(settings_override)

    app.register_blueprint(page)
    app.register_blueprint(contact)
    extensions(app)
    middleware(app)
    error_templates(app)
    # exception_handler(app)
    template_processors(app)
    return app


...


def middleware(app):
    """
    Register 0 or more middleware (mutates the app passed in).

    :param app: Flask application instance
    :return: None
    """
    # Swap request.remote_addr with the real IP address even if behind a proxy.
    app.wsgi_app = ProxyFix(app.wsgi_app)

    return None

This is my Dockerfile

...

# Expose port 8000
EXPOSE 8000
ENV PORT 8000


CMD gunicorn -c "python:config.gunicorn" "snakeeyes.app:create_app()" --timeout 1000

This is my config/gunicorn.py file

# -*- coding: utf-8 -*-

bind = "0.0.0.0:8000"
accesslog = "-"
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" in %(D)sµs'
Filipe Ferminiano
  • 8,373
  • 25
  • 104
  • 174

0 Answers0