jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
895 stars 221 forks source link

uWSGI server not working like the docs #271

Open jotauses opened 5 years ago

jotauses commented 5 years ago

When I run the command in the docs: uwsgi --virtualenv /path/to/virtualenv --http-socket /path/to/web.socket --gevent 1000 --http-websockets --workers=2 --master --module wsgi_websocket

I get the next error:

Traceback (most recent call last):
  File "/home/ubuntu/deploy/bbrainers/bbrainers/wsgi_websocket.py", line 13, in <module>
    from ws4redis.uwsgi_runserver import uWSGIWebsocketServer
  File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/ws4redis/uwsgi_runserver.py", line 5, in <module>
    from ws4redis.wsgi_server import WebsocketWSGIServer
  File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/ws4redis/wsgi_server.py", line 10, in <module>
    django.setup()
  File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
jrief commented 5 years ago

there are so many different ways uWSGI is compiled. For instance the logger can be statically linked or is available as a 3rd party module. Presumably the latter is your problem.

jotauses commented 5 years ago

I had to put os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_app.settings") before django_setup() in wsgi_server.py

Now the socket connects but I get this error and the message does not send:

`Traceback (most recent call last): File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django_websocket_redis-0.5.2-py3.6.egg/ws4redis/wsgi_server.py", line 131, in call recvmsg = RedisMessage(websocket.receive()) File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django_websocket_redis-0.5.2-py3.6.egg/ws4redis/uwsgi_runserver.py", line 31, in receive raise WebSocketError(e) ws4redis.exceptions.WebSocketError: unable to receive websocket message [pid: 25855|app: 0|req: 2/4] 127.0.0.1 () {44 vars in 987 bytes} [Mon Jul 30 11:53:24 2018] GET /ws/notify?subscribe-broadcast/ => generated 38 bytes in 10736 msecs (HTTP/1.1 101) 4 headers in 184 bytes (3 switches on core 999) WebSocketError: unable to receive websocket message Traceback (most recent call last): File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django_websocket_redis-0.5.2-py3.6.egg/ws4redis/uwsgi_runserver.py", line 28, in receive return uwsgi.websocket_recv_nb() OSError: unable to receive websocket message

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django_websocket_redis-0.5.2-py3.6.egg/ws4redis/wsgi_server.py", line 131, in call recvmsg = RedisMessage(websocket.receive()) File "/home/ubuntu/deploy/bbrainers/venv/lib/python3.6/site-packages/django_websocket_redis-0.5.2-py3.6.egg/ws4redis/uwsgi_runserver.py", line 31, in receive raise WebSocketError(e) ws4redis.exceptions.WebSocketError: unable to receive websocket message [pid: 25856|app: 0|req: 3/5] 127.0.0.1 () {44 vars in 987 bytes} [Mon Jul 30 11:53:35 2018] GET /ws/notify?subscribe-broadcast/ => generated 20 bytes in 3097 msecs (HTTP/1.1 101) 4 headers in 184 bytes (3 switches on core 998)`

jee1mr commented 5 years ago

Any solution?