UWSGI нет модуля с именем uwsgi - PullRequest
0 голосов
/ 07 октября 2019

Надеюсь, у тебя все хорошо. У меня проблема с 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)

Traceback (последний вызов был последним): Файл "websocket.py"строка 6, в импорте uwsgi ModuleNotFoundError: нет модуля с именем 'uwsgi'

1 Ответ

0 голосов
/ 07 октября 2019

Как вы начинаете свой код?

Если вы хотите импортировать uwsgi, у вас есть (если я правильно помню) запустить исполняемый файл uwsgi, который, в свою очередь, запустит работников uwsgi. Эти работники uwsgi могут затем импортировать uwsgi.

...