python - UWSGI 没有名为 uwsgi 的模块
问题描述
我希望你做得很好。我有问题
import uwsgi
感谢您的帮助,我的 rabbitmq 正在幕后工作,不用担心
我已经安装了版本 2.0.15 和 2.0.18 的 uwsgi,但我尝试了它仍然不起作用我的目的是导入 uwsgi 和
uwsgi.websocket_handshake(
env['HTTP_SEC_WEBSOCKET_KEY'],
env.get('HTTP_ORIGIN', '')
)
如果我不能导入 uwsgi 所以我不能使用 uwsgi.websocker_handshake
"""Receive messages over from RabbitMQ and send them over the websocket."""
import sys
import pika
import uwsgi
def application(env, start_response):
"""Setup the Websocket Server and read messages off the queue."""
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost')
)
channel = connection.channel()
exchange = env['PATH_INFO'].replace('/', '')
channel.exchange_declare(
exchange=exchange, exchange_type='fanout'
)
# exclusive means the queue should be deleted once the connection is closed
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue # random queue name generated by RabbitMQ
channel.queue_bind(exchange=exchange, queue=queue_name)
uwsgi.websocket_handshake(
env['HTTP_SEC_WEBSOCKET_KEY'],
env.get('HTTP_ORIGIN', '')
)
def keepalive():
"""Keep the websocket connection alive (called every 30 seconds)."""
print('PING/PONG...')
try:
uwsgi.websocket_recv_nb()
connection.add_timeout(30, keepalive)
except OSError as error:
connection.close()
print(error)
sys.exit(1) # Kill process and force uWSGI to Respawn
keepalive()
while True:
for method_frame, _, body in channel.consume(queue_name):
try:
uwsgi.websocket_send(body)
except OSError as error:
print(error)
sys.exit(1) # Force uWSGI to Respawn
else:
# acknowledge the message
channel.basic_ack(method_frame.delivery_tag)
回溯(最后一次调用):文件“websocket.py”,第 6 行,导入 uwsgi ModuleNotFoundError:没有名为“uwsgi”的模块
解决方案
你如何开始你的代码?
如果你想导入 uwsgi,你可以(如果我没记错的话)启动 uwsgi 可执行文件,然后它会启动 uwsgi 工作程序。然后这些 uwsgi 工作者可以导入 uwsgi。
推荐阅读
- mysql - 如何执行内连接
- c++ - FreeImage: 为什么它不适用于 cairo?
- reactjs - 高效更新 React useState 对象
- java - 相当于 Micronaut 中的 javax.ws.rs NameBinding?
- java - 如何使用 Mockito 模拟类中的一个静态方法?
- database - Oracle中的“主从”表复制
- data-visualization - Qlik 集合分析,通过修饰符部分选择字段,同时忽略相同的字段选择
- machine-learning - Elephas 教程错误 - ValueError:无法解释优化器标识符
- php - 如何检查php和sql中两个日期之间的日期?
- apache-nifi - 在 Nifi 中,我们如何在 putMongo 之前删除Mongo(来自 ConvertRecord 的流文件)