Deploying a Quart Python app in Google App Engine - python

I'm trying to deploy a Quart based python app via Google Cloud's App Engine Standard. However, I keep getting the following error:
Traceback (most recent call last):
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 284, in handle
keepalive = self.handle_request(req, conn)
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 333, in handle_request
respiter = self.wsgi(environ, resp.start_response)
TypeError: __call__() missing 1 required positional argument: 'send'
I know that Quart is an ASGI solution and Google App Engine is a Serverless setting. One of the recommendations for deploying quart into AWS Lambda was to use Magnum. Does that work for Google Cloud App Engine as well?
Any help would be appreciated.

From https://github.com/pgjones/quart/issues/68:
Quart is an ASGI framework, rather than a WSGI framework, which means that it cannot work with serverless. It can work with Mangum, which is an ASGI alternative to serverless.
This also means that Quart will not be compatible with App Engine, Cloud Functions, etc.
However, it would work well with Cloud Run via a HTTP server that supports ASGI such as Uvicorn.

Magnum is an adapter for using ASGI applications with AWS Lambda & API Gateway and is not tested for Google GCP.
I recommend following the suggestion of #di and use Uvicorn with Cloud Run.

Related

FastAPI python app error on Azure App Service

I have a python web application that is using FastAPI. It works locally, but when I deploy it to a free linux Azure App Service (using GitHub Actions) and try to load the site it says "Internal Server Error". When I pull up the application logs I see the following error message
2023-02-06T23:44:30.765055894Z [2023-02-06 23:44:30 +0000] [90] [ERROR] Error handling request /
2023-02-06T23:44:30.765101490Z Traceback (most recent call last):
2023-02-06T23:44:30.765109589Z File "/opt/python/3.10.9/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 136, in handle
2023-02-06T23:44:30.765116389Z self.handle_request(listener, req, client, addr)
2023-02-06T23:44:30.765122088Z File "/opt/python/3.10.9/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
2023-02-06T23:44:30.765128688Z respiter = self.wsgi(environ, resp.start_response)
2023-02-06T23:44:30.765134688Z TypeError: FastAPI.__call__() missing 1 required positional argument: 'send'
Any suggestions on how to fix this issue?
I was able to resolve this issue by adding the following custom startup command in the Azure App Service Configuration General Settings
python -m uvicorn app:app --host 0.0.0.0
As h4z3 pointed out, gunicorn is wsgi and fastapi is asgi so I had to change the startup command to use uvicorn. Additional details can be found in the Azure docs here: https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#example-startup-commands

Choosing an appropriate azure service to deploy repetitive python task

I have been attempting to deploy a web scraper written in python for the past few weeks on azure. I initially tried to do this in an azure app service by building pushing a docker image to the service. I have had success previously with this method when deploying a flask rest api. Unfortunately the time out limit of the azure app service meant that the web scraper container is terminated as it is does not give a proper response when azure attempts to get a response.
I have since tried setting up a windows based app service in order to create an azure WebJob however, this has the problem of being capped at python 3.6 which i believe is causing import problems. I cannot import the "requests" module which is essential for the scraper to work correctly. I have a requirements.txt inside the zip i upload for the webjob but this doesnt seem to allow the importing of this module either. Is there a way to import modules from inside the webjob or is there another/better way to deploy a repetitive task on azure that doesnt have to give an api response like a normal azure app service deployment.
Below is the error i am receiving in the webjob logs :
[12/19/2020 16:36:48 > 658fd3: SYS INFO] Run script 'run.py' with script host - 'PythonScriptHost'
[12/19/2020 16:36:48 > 658fd3: SYS INFO] Status changed to Running
[12/19/2020 16:36:48 > 658fd3: ERR ] Traceback (most recent call last):
[12/19/2020 16:36:48 > 658fd3: ERR ] File "run.py", line 12, in <module>
[12/19/2020 16:36:48 > 658fd3: ERR ] import requests
[12/19/2020 16:36:48 > 658fd3: ERR ] ModuleNotFoundError: No module named 'requests'
Any help is greatly appreciated thank you.
You can use Azure's Serverless feature called Functions. If you want to make more use of it, then make a docker container with any image you want and upload it as your function, but beware of cold starts

ERROR: An app.yaml (or appengine-web.xml) file is required to deploy this directory as an App Engine application

When I try deploying my Python code through Cloud Build to Google App Engine (GAE) I receive the following ERROR message:
ERROR: An app.yaml (or appengine-web.xml) file is required to deploy this directory as an App Engine application
ERROR: (gcloud.app.deploy) [/workspace] could not be identified as a valid source directory or file.
ERROR: build step 0 "gcr.io/google.com/cloudsdktool/cloud-sdk" failed: step exited with non-zero status
Can someone explain what might be causing this error?
A Python app in App Engine is configured using an app.yaml, that contains CPU, memory, network and disk resources, scaling, and other general settings including environment variables. From looking at this error message your app.yaml appears to be missing. You can read more about how to configure your application here: Configuring your App with app.yaml

"Connection in use" error in GCP app engine

I am new to GCP App engine. I am trying to make web server using flask on App engine. I tested the version of my code on localhost and it is working fine. But when I am trying to deploy it in the App Engine of GCP it is giving me this strange error "app logs".
error logs
Here is my code for the flask
app.run(threaded = True, host='127.0.0.1', port=80)
Thanks!!
You don't need to call app.run() in your main.py file -- App Engine will do that for you. Simply initialize the app variable in this file instead.

AssertionError: No api proxy found for service "xmpp"

I am trying to run gae app without dev_appserver.py, and have following error
AssertionError: No api proxy found for service "xmpp"
room = webrtc.Room.get_by_key_name(room_key)
I found in the app.yaml inbound_services:
- channel_presence
How to enable channel_presence directly in application.py
Unless otherwise specified, libraries included with the App Engine SDK are expected only to work within the App Engine environment. You cannot just import the XMPP library included with the App Engine SDK and expect it to work in a non-GAE application.

Categories