首页 > 解决方案 > Flask-SocketIO 在 Azure 上不起作用

问题描述

我有一个网站在本地托管时可以完美运行,但在 Azure 上,socketio 请求会导致 http 400 错误。这是一个使用 flask-socketio 的 Python 烧瓶应用程序。我在本地连接的套接字是“ http://127.0.0.1:5000 ”,但在 Azure 上我连接到http://myurl.azurewebsites.net:80因为 Azure 文档说它在端口 80 和 443 上侦听。我'正在使用带有 jquery 的 javascript,这就是我创建套接字的方式:

var socket = io.connect('http://myurl.azurewebsites.net:80');

我从遇到这个问题的人那里发现了很多问题,但他们似乎都在使用 node.js,并且解决方案涉及 node.js 的 require() 方法。我找不到仅使用 javascript 或 jquery 的解决方案。这甚至可能吗?谢谢。

标签: javascriptjqueryazure-web-app-serviceflask-socketio

解决方案


我试图重现您的问题但失败了。我按照这里的示例进行操作。部署到 Azure,安装需求并在 Azure 中启用 Web Sockets 后portal > App > Application Settings,一切正常。请参考我的组件。

在此处输入图像描述

输出

在此处输入图像描述

我的 web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <webSocket enabled="true" />
  <handlers>
   <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
  </handlers>

  <httpPlatform processPath="D:\home\Python27\python.exe" arguments="run_waitress_server.py" requestTimeout="00:04:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true">
   <environmentVariables>
    <environmentVariable name="PYTHONPATH" value="D:\home\site\wwwroot" />
    <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
   </environmentVariables>
  </httpPlatform>

</system.webServer>
</configuration>

希望它可以帮助你。


推荐阅读