UWSGI没有名为uwsgi的模块

问题描述 投票:0回答:1

我希望你一切都好。我有问题import uwsgi感谢您的帮助,我的rabbitmq正在幕后工作,不用担心

我已经安装了uwsgi,该版本为2.0.15和2.0.18,但我仍然尝试不起作用,我的目的是导入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)

追踪(最近通话):在第6行的文件“ websocket.py”中导入uwsgiModuleNotFoundError:没有名为“ uwsgi”的模块

我希望你一切都好。我在导入uwsgi时遇到问题感谢您的帮助,我的Rabbitmq在后台运行,不用担心,我已经安装了2.0.15和2.0.18版本的uwsgi和...

python django websocket uwsgi wsgi
1个回答
0
投票

您如何开始编写代码?

© www.soinside.com 2019 - 2024. All rights reserved.