Select to view content in your preferred language

Deploying flask based REST service - works in development mode, crashes when launched by uvicorn.

947
0
11-03-2023 01:50 PM
ChuckBenton
Frequent Contributor

I've developed a REST service that uses flask and runs in flask's development environment without issue. It is installed in a ArcGIS python clone, using the arcgis, arcpy, flask packages. In development mode I see the following. Note it responds properly with a 200 response when queried by a client.

Screen Shot 2023-11-03 at 4.34.08 PM.png

I then try running the app using the only production WSGI server available via ArcGIS Pro's Package Manager. I get the following error.

(arcgispro-py3-clone-3) C:\Users\Administrator\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-3\test_flask> uvicorn app:app --host 0.0.0.0 --port 8002
starting
starting
←[32mINFO←[0m: Started server process [←[36m2728←[0m]
←[32mINFO←[0m: Waiting for application startup.
←[32mINFO←[0m: ASGI 'lifespan' protocol appears unsupported.
←[32mINFO←[0m: Application startup complete.
←[32mINFO←[0m: Uvicorn running on ←[1mhttp://0.0.0.0:8002←[0m (Press CTRL+C to quit)

At this point the app is running fine. I then send the same request as done earlier with the following response:


←[31mERROR←[0m: Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-3\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 407, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "C:\Users\Administrator\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-3\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
File "C:\Users\Administrator\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-3\lib\site-packages\uvicorn\middleware\asgi2.py", line 19, in __call__
instance = self.app(scope)
TypeError: __call__() missing 1 required positional argument: 'start_response'
←[32mINFO←[0m: 67.253.80.75:54898 - "←[1mGET / HTTP/1.1←[0m" ←[91m500 Internal Server Error←[0m

The Internal Server error response is immediate.

 

There's lots of info to be found on this error in the context of Django or other environments, but not specific to ArcGIS. I've discovered that in the cloned environment using packages that are not in Package Manager is a non-starter.

Any ideas are most welcome!!

Chuck

 

Tags (3)
0 Kudos
0 Replies