django / daphne

Django Channels HTTP/WebSocket server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: not enough values to unpack (expected 2, got 1)

olitomas opened this issue · comments

When I start Daphne it runs for a few seconds and then crashes with this error.

Traceback (most recent call last):
  File "/var/www/live/<myProject>/venv/bin/daphne", line 8, in <module>
    sys.exit(CommandLineInterface.entrypoint())
  File "/var/www/live/<myProject>/venv/lib/python3.7/site-packages/daphne/cli.py", line 170, in entrypoint
    cls().run(sys.argv[1:])
  File "/var/www/live/<myProject>/venv/lib/python3.7/site-packages/daphne/cli.py", line 232, in run
    application = import_by_path(args.application)
  File "/var/www/live/<myProject>/venv/lib/python3.7/site-packages/daphne/utils.py", line 11, in import_by_path
    module_path, object_path = path.split(":", 1)
ValueError: not enough values to unpack (expected 2, got 1)

Im running Python 3.7.8 in a virtual enviroment.

Redis server v=5.0.9

From pip freeze:
channels==3.0.4
channels-redis==3.3.1
daphne==3.0.2
Django==3.0.8

Can anyone nudge me in the right direction (I googled ALOT before posting here). Any input would be greatly appreciated 😊

The command you're running should be like daphne -b 0.0.0.0 -p 8001 django_project.asgi:application . But you didn't use a : and point to the application. Make sense?

Everything in my config file is fine. I don't have anything missing, and I still get this error. Do you know what could be the problem? Here's my daphne startup bash file:

#!/bin/bash

NAME="outpostsite-daphne"  # Name of the application
DJANGODIR=/home/admin/code/outpost/outpostsite  # Django project directory
DJANGOENVDIR=/home/admin/code/outpost/env  # Django project env

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source /home/admin/code/outpost/env/bin/activate
source /home/admin/code/outpost/outpostsite/.env
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Start daphne
exec ${DJANGOENVDIR}/bin/daphne -u /home/admin/code/outpost/env/run/daphne.sock --access-log - --proxy-headers outpostsite.asgi:application

@fullyHouse do you have exactly the same error? Plelase provide the stack trace.

The error is exactly the same

Is it ValueError: not enough values to unpack (expected 2, got 1), with the exact same traceback? That doesn't seem likely since you are using the colon in your application specification.

I can run a command analogous to yours with no problem:

$ daphne -u /tmp/daphne.sock --access-log - --proxy-headers example.asgi:application
2021-11-01 10:17:30,347 INFO     Starting server at unix:/tmp/daphne.sock

Yeah, the error is exactly the same, with the exact same traceback. Maybe there is something else wrong with the config? Or shall I just use a different command?

I cannot see how you could get the same error. There isn't an alternative way to invoke Daphne. You're going to need to provide more more information, such as an example project that recreates this error.

@fullyHouse @adamchainz the colon was definitely the problem for me.

@olitomas Can you show me your daphne startup code, maybe there's something wrong with mine.
@adamchainz This error couldn't have happened anywhere else, because I get it from the "daphne" logs when I try to launch it using supervisor. Just in case you want to see it, here's my supervisor config:

[fcgi-program:daphne]
socket=tcp://localhost:8000
command=/home/admin/code/outpost/env/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --endpoint fd:fileno=0 --ac$
directory=/home/admin/code/outpost/outpostsite/
numprocs=1
autostart=1
autorestart=1
stopasgroup=1
user=admin
redirect_stderr=true
stdout_logfile = /home/admin/code/outpost/logs/daphne/access.log
stderr_logfile = /home/admin/code/outpost/logs/daphne/error.log
stdout_logfile_maxbytes=50MB
stderr_logfile_maxbytes=50MB
stdout_logfile_backups=10
stderr_logfile_backups=10
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8

This is my daphne.service (being run by systemd)

[Unit]
Description=WebSocket Daphne Service
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=<MY WOKRING DIRECTORY>
ExecStart=/<PROJECT LOCATION>/venv/bin/python /<PROJECT LOCATION>/venv/bin/daphne -b 0.0.0.0 -p 8001 <PROJECT NAME>.asgi:application
Restart=on-failure

[Install]
WantedBy=multi-user.target

alright, thanks, I'll try something like that

ok, I changed some stuff up, I am still using the previous start up file, which I sent in one of the comments above.
And now I get this error:

2021-11-01 15:43:00,617 CRITICAL Listen failure: [Errno 2] No such file or directory: '22538' -> b'/home/admin/code/outpost/env/run/daphne.sock.lock'

I realised that I don't actually have such file. What shall I change that direction in the config to?

Hmm, my guess would be that Daphne is trying to create a lockfile but cant because of permission issues.

But I have all permissions for the env/ directory, so I don't know why. Maybe it's not even trying to create it at all