0

I deployed a Python 3.10 + Flask Websocket on Azure Web App. During runtime, it falls back to pooling. In the stream log, there are these events below:

 - 2023-07-05T08:31:25.786184617Z     raise RuntimeError('You need to
   use the gevent-websocket server. '
   
   2023-07-05T08:31:25.786188575Z RuntimeError: You need to use the
   gevent-websocket server. See the Deployment section of the
   documentation for more information.

How can I fix this? I already have these two in my requirements.txt:

gevent==22.10.2
gevent-websocket==0.10.1

Is there any special setting I need to set in the Azure Web App ?

user2467491
  • 73
  • 1
  • 7

2 Answers2

0

In the configuartion, you must first turn ON the WEB SOCKETS option

From DOC to install package from required.txt.

  • use pip to install the packages you defined python -m pip install -r requirements.txt, pip install flask flask-socketio
  • Create a file requirements.txt with the following content.
gevent

gevent-websocket
SCM_DO_BUILD_DURING_DEPLOYMENT = true

enter image description here

  • Configure your Python webapp using WSGI on Azure IIS, and you can use the instructional content as a guide.

  • Refer to this SO and git for more details.

Sampath
  • 810
  • 2
  • 2
  • 13
  • 0. In the configuration, you must first turn ON the WEB SOCKETS option -> This option no longer available. Maybe it is enabled by default? ``` 1. Installed: gevent gevent-websocket 2. Added to requirements.txt: gevent gevent-websocket 3. Added .deployment [config] SCM_DO_BUILD_DURING_DEPLOYMENT=true 4. Redeployed but still in polling mode. ``` This is the sample I tried: https://github.com/miguelgrinberg/Flask-SocketIO/tree/main/example – user2467491 Jul 07 '23 at 06:39
  • for more details to this [SO](https://stackoverflow.com/questions/50971911/host-name-and-port-for-python-websockets-on-azure-web-apps) and [SO1](https://stackoverflow.com/questions/43438910/python-websocket-support-on-azure-web-appservice). – Sampath Jul 07 '23 at 06:50
  • Tried the web.config way but also not working. Python on Windows no longer supported. Does web.config still relevant? – user2467491 Jul 07 '23 at 09:02
  • For issue-related WebSocket refer to [this](https://github.com/MicrosoftDocs/azure-docs/issues/31771). – Sampath Jul 07 '23 at 09:10
  • Tried the startup commands such as 'gunicorn -k gevent -w 1 module:app' but throwing error – user2467491 Jul 07 '23 at 09:11
  • The faq link in the link above is going to 404. And my env is python in linux web app. Another link [link](https://learn.microsoft.com/en-us/troubleshoot/azure/app-service/faqs-app-service-linux#feedback) doesn't have much info for Python, – user2467491 Jul 07 '23 at 09:15
  • it loads well while clicking on [it](https://github.com/MicrosoftDocs/azure-docs/issues/31771). Using the WebSocket server is required, according to the error message you are currently seeing. In your requirements.txt file, you've already installed it however, you might still need to make some adjustments in the Azure Web App. To install a package from requirements.txt. – Sampath Jul 07 '23 at 09:22
  • I meant the link Content Source: articles/app-service/containers/app-service-linux-faq.md in the article – user2467491 Jul 11 '23 at 03:18
  • any way, I installed simple-websocket, My requirement txt: https://gist.github.com/huislaw/fe13eaeb41c7b656e56112a0e48bb174, Deployed to: https://testhssocketio.azurewebsites.net/ , It shows connected, but Current transport is: polling, Deployment log: https://gist.github.com/huislaw/46943d3591157a72275cf8dc997eb86b (Doesn't seems to have error) , After enabling log for app service I get this error: https://gist.github.com/huislaw/c7bc0e3d14c185fc6001ffa86c4685e8 , I'm not sure what is this error about. Do you have any idea? – user2467491 Jul 11 '23 at 03:19
  • it is solved by adding to App Service's Startup Command: gunicorn -w 1 --threads 1000 app:app – user2467491 Jul 17 '23 at 06:10
  • Good that issue resolved with ```gunicorn -w 1 --threads 1000 app:app``` – Sampath Jul 17 '23 at 07:37
0

Working steps:

  1. Install simple-websocket
  2. Update requirements.txt with simple-websocket
  3. Add to App Service's Startup Command: gunicorn -w 1 --threads 1000 app:app
  4. Redeploy
user2467491
  • 73
  • 1
  • 7