javascript - 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 的解决方案。这甚至可能吗?谢谢。
解决方案
我试图重现您的问题但失败了。我按照这里的示例进行操作。部署到 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>
希望它可以帮助你。
推荐阅读
- c++ - 在 std::tuple 上“迭代”并可以访问所有构造函数
- javascript - 使用单个按钮打开和关闭图片 (JavaScript)
- spring - Spring - 在@EventListener 上分离但附加在@Service 类中的相同实体
- swagger - 注入javascript文件
- wordpress - 网格模板区域项目在特定屏幕尺寸上消失
- node.js - Discord bot setRole 命令只能随机工作
- javascript - 仅显示数组的最后一个版本
- python - 如何定义保存在一个 exe 文件中的绝对路径?
- ruby - 无法在 Manjaro 18.1 上运行 ruby IRB
- c# - SSIS从平面文件中过滤记录