首页 > 解决方案 > Python eventlet 库:TypeError:'coroutine' 对象不可迭代

问题描述

我正在使用python socket ioeventlet库创建一个 wsgi 服务器。我正在使用 socket io 库来利用 web socket。这是我在服务器端的代码:

import eventlet
import eventlet.wsgi

import  socketio

static_files = {
    '/': './public/index.html',
    '/public/style.css' : './public/style.css',
    '/public/index.js' : './public/index.js',
}

sio = socketio.AsyncServer(cors_allowed_origins=['*'])
app = socketio.WSGIApp(sio, static_files=static_files)

eventlet.wsgi.server(eventlet.listen(('', 8080)), app)

在 js 代码中,我在浏览器上运行时通过 websocket 连接:

const socket = io("http://localhost:8080");

从浏览器连接到 localhost:8080 后出现错误;该网站已提供服务,但服务器崩溃并显示以下错误(“TypeError:'coroutine' object is not iterable”): 在此处输入图像描述 我该如何解决这个问题?

标签: pythonsocket.iowsgieventlet

解决方案


推荐阅读