Py学习  »  Python

electron/socket.io client-python socketio/aiohttp server//连接失败

The Fool • 6 年前 • 844 次点击  

此websocket连接失败。有趣的是这几天前还在起作用。我把电子从6降到了5.0.6,但这没用。

enter image description here enter image description here

服务器

from aiohttp import web
import socketio


app = web.Application()
sio = socketio.AsyncServer()
# or sio = socketio.AsyncServer(cors_allowed_origins='*')
sio.attach(app)

@sio.on('connect')
async def user_connected(sid, arg):
    print(sid)
    print(arg)

if __name__ == '__main__':
    web.run_app(app)

客户端(也从纯节点测试)

const con = 'http://0.0.0.0:8080';
const socket = require('socket.io-client').connect(con);

socket.on('connect', (e) => console.log(e));

sio = socketio.AsyncServer(cors_allowed_origins='*')

当我现在从electron/node运行这个程序时,得到的错误与最初的相同,加上一个键错误: enter image description here

因为它以前工作过,现在不在两台不同的机器上,而且只有一个最小的示例项目,所以我不知道是什么导致了这一切。

请帮我堆人。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50543
文章 [ 1 ]  |  最新文章 6 年前
The Fool
Reply   •   1 楼
The Fool    6 年前

然而,仅仅 pip install python-socketio 你必须安装 python-enginio 手动,因为有CORS头修复。

我的Pipfile如下所示:

[packages]
aiohttp = "*"
aiohttp-cors = "*"
python-enginio = {git = "https://github.com/miguelgrinberg/python-engineio/",ref = "master"}
python-socketio = "*"

别忘了在服务器端允许CORS。

sio = socketio.AsyncServer(cors_allowed_origins='*')