daphne -b 0.0.0.0 -p 8000 mabtest.asgi.main
ERROR:
ValueError: not enough values to unpack (expected 2, got 1)
Any suggestions?
On Thursday, September 23, 2021 at 9:45:59 AM UTC-5 jmenen...@gmail.com wrote:
You are missing a main attribute on your asgi.py file. Try with daphne -b 0.0.0.0 -p 8001 mabtest.asgi:applicationEl miércoles, 22 de septiembre de 2021 a las 20:37:50 UTC, mab.mo...@gmail.com escribió:Hello,I am attempting to add asgi/channels to an existing django project/web app. I was originally able to get channels to work via python manage.py runserver ....I am trying to deploy the project in production but cannot cat Daphne to start. Error messages and relevant files below.Questions1. Can someone provide direction on getting the daphne error corrected?2. Does anyone have any instruction on getting channels to work with daphne and nginx?Thank you.-------------------------Attempting to run daphne server with error ...(mabtest) marc@mymachine:~/webdev/mabtest$ daphne -b 0.0.0.0 -p 8001 mabtest.asgi:mainTraceback (most recent call last):File "/home/marc/Env/mabtest/bin/daphne", line 8, in <module>sys.exit(CommandLineInterface.entrypoint())File "/home/marc/Env/mabtest/lib/python3.8/site-packages/daphne/cli.py", line 170, in entrypointcls().run(sys.argv[1:])File "/home/marc/Env/mabtest/lib/python3.8/site-packages/daphne/cli.py", line 232, in runapplication = import_by_path(args.application)File "/home/marc/Env/mabtest/lib/python3.8/site-packages/daphne/utils.py", line 14, in import_by_pathtarget = getattr(target, bit)AttributeError: module 'mabtest.asgi' has no attribute 'main'## NOTES ##- project name: mabtest- app name: main- redis is installed----- mabtest/asgi.py -------from .wsgi import *import osimport djangofrom django.core.asgi import get_asgi_applicationfrom channels.routing import get_default_applicationfrom channels.auth import AuthMiddlewareStackfrom channels.routing import ProtocolTypeRouter, URLRouterfrom django.conf.urls import urlfrom main.routing import ws_urlpatternsos.environ.setdefault("DJANGO_SETTINGS_MODULE", "mabtest.settings")django.setup()application = get_default_application()----- main/routing.py -----from django.urls import pathfrom .consumers import ws_consumer# Set the path to call the consumerws_urlpatterns = [path('ws/main/', ws_consumer.as_asgi())-----import json#from channels.generic.websocket import WebsocketConsumerfrom channels.generic.websocket import AsyncWebsocketConsumerfrom datetime import datetimefrom time import sleep# Define the consumer class to send the data through WebsocketConsumerclass ws_consumer(AsyncWebsocketConsumer):# make a web socket connectionasync def connect(self):# make a channel layer and group so it can display on multiple browers tabsself.group_name = "aprs"await self.channel_layer.group_add(self.group_name,self.channel_name)await self.accept()# group creates a message in key value pair formatnow = datetime.now()await self.channel_layer.group_send(self.group_name,{'type': 'my_messages', # must match function def name below'my_message_1': 'This is message #1','my_message_2': 'This is message #2','my_message_3': now.strftime("%H:%M:%S"),})# receive message from group and send it through websocketasync def my_messages(self, event):# collect informationmy_message_1 = event['my_message_1']my_message_2 = event['my_message_2']my_message_3 = event['my_message_3']# send information via json and websocketawait self.send(text_data=json.dumps({'my_message_1': my_message_1,'my_message_2': my_message_2,'my_message_3': my_message_3,}))# self.accept()# while(True):# now = datetime.now()# self.send(json.dumps({'timeValue': now.strftime("%H:%M:%S")}))# sleep(1)# disconnects from websocketasync def disconnect(self, close_code):await self.channel_layer.group_discard(self.group_name,self.channel_name)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/29c155be-fab3-4fe2-8821-de3aa56abd0fn%40googlegroups.com.
No comments:
Post a Comment