ecerami / fastapi_azure Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
We are seeing this error reported in our sentry for a FastApi Azure function
partially initialized module 'anyio._backends._asyncio' has no attribute 'Event' (most likely due to a circular import)
We based our app on your repo and the http_asgi.py. That is the only place where we import asyncio. We don't import anyio at all.
Has someone the same problem?
Found your Medium post some months ago. Got the API working on Azure and running for a couple of months now, thanks for that.
But.. I tried to update the API today and pushed the new code to Azure and ended up with http 500 error codes. Seems to be an error in the http_asgi.py if i am not mistaken. This is the error i got from the Application Insights.
Do you know what the problem might be?
Exception while executing function: Functions.my-appname <--- Result: Failure Exception: TypeError: '<' not supported between instances of 'NoneType' and 'int' Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 402, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 611, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/my-appname/__init__.py", line 230, in main return AsgiMiddleware(app).handle(req, context) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure/functions/_http_asgi.py", line 146, in handle return self._handle(req, context) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure/functions/_http_asgi.py", line 152, in _handle asgi_response = self._loop.run_until_complete( File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure/functions/_http_asgi.py", line 65, in from_app await app(scope, res._receive, res._send) File "/home/site/wwwroot/.python_packages/lib/site-packages/fastapi/applications.py", line 212, in __call__ await super().__call__(scope, receive, send) File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/applications.py", line 119, in __call__ await self.middleware_stack(scope, receive, send) File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/middleware/errors.py", line 181, in __call__ raise exc File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/middleware/errors.py", line 159, in __call__ await self.app(scope, receive, _send) File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/exceptions.py", line 87, in __call__ raise exc File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/exceptions.py", line 76, in __call__ await self.app(scope, receive, sender) File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/routing.py", line 659, in __call__ await route.handle(scope, receive, send) File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/routing.py", line 259, in handle await self.app(scope, receive, send) File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/routing.py", line 61, in app response = await func(request) File "/home/site/wwwroot/.python_packages/lib/site-packages/fastapi/routing.py", line 216, in app solved_result = await solve_dependencies( File "/home/site/wwwroot/.python_packages/lib/site-packages/fastapi/dependencies/utils.py", line 465, in solve_dependencies response = response or Response( File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/responses.py", line 50, in __init__ self.init_headers(headers) File "/home/site/wwwroot/.python_packages/lib/site-packages/starlette/responses.py", line 77, in init_headers and not (self.status_code < 200 or self.status_code in (204, 304))
Hello,
I tried to follow your tutorial unfortunately, when I am running the azure function locally, I have this error in verbose mode:
[2022-02-20T18:36:52.519Z] Reading functions metadata
[2022-02-20T18:36:52.519Z] 0 functions found
[2022-02-20T18:36:52.538Z] 0 functions loaded
[2022-02-20T18:36:52.554Z] Generating 0 job function(s)
[2022-02-20T18:36:52.568Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
I don't understand why the app isn't loaded correctly while my configuration looks like this :
function.json
{
"scriptFile": "app.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post",
"put",
"patch",
"delete"
],
"route": "/{*route}"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
app.py
import azure.functions as func
from http_asgi import AsgiMiddlewarefrom app import app
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
return AsgiMiddleware(app).handle(req, context)
app/init.py
from fastapi import FastAPI, Depends
from app.auth.jwt_bearer import JWTBearer
from app.routes.device import router as device_router
from app.routes.auth import router as admin_router
from app.routes.user import router as user_router
from app.routes.transceiver import router as transceiver_routerapp = FastAPI()
token_listener = JWTBearer()
app.include_router(admin_router, tags=["Auth"], prefix="/auth")
app.include_router(user_router, tags=["Users"], prefix="/users", dependencies=[Depends(token_listener)])
app.include_router(device_router, tags=["Devices"], prefix="/devices", dependencies=[Depends(token_listener)])
app.include_router(user_router, tags=["Transceivers"], prefix="/transceivers", dependencies=[Depends(token_listener)])
Could you please have a look and help me on this one?
Thank you,
Romain
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.