1

I developed an python webcrawler application based on scrapy and packaged it as a klein application (klein framework)

When I test it locally it everything works as expected, however when I deploy it to google app engine I get a "502 bad gateway". I found other mentions of the 502 error but nothing in relation to the klein framework I am using. So I was just wondering if app engine is maybe incompatible with it.

This is my folder structure

    app
    --app.yaml
    --main.py
    --requirements.txt

The contents of app.yaml

    runtime: python37
    
    instance_class: F2
    
    handlers:
    - url: /.*
      secure: always
      redirect_http_response_code: 301
      script: auto

The contents of main.py


    from klein import route, run
    
    @route("/")
    def landing_page(request):
        return "HELLO"
    
    if __name__== "__main__":
        run(host='127.0.0.1', port=8080)

sirluk
  • 31
  • 6
  • I tried to run this code locally and it works when using the “python” command, but not when using gunicorn, or the other supported [web servers supported by App Engine](https://cloud.google.com/appengine/docs/standard/python3/runtime#application_startup) You may want Cloud Run to replicate the environment you have locally. – mgoya Aug 04 '20 at 15:56
  • Thanks for you answer, I also started to migrate to cloud run in the meantime. It does work there – sirluk Aug 04 '20 at 19:25

1 Answers1

1

App Engine requires your main.py file to declare an app variable which corresponds to a WSGI Application.

Since Klein is an asynchronous web framework, it is not compatible with WSGI (which is synchronous).

Your best option would be to use a service like Cloud Run, which would allow you to define your own runtime and use an asynchronous HTTP server compatible with Klein.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82