question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

channels/consumer.py: encoding with 'idna' codec failed (UnicodeError: label empty or too long)

See original GitHub issue

Cloned https://github.com/andrewgodwin/channels-examples/tree/master/multichat, ran successfully on local, but failed on Heroku, ERROR is "encoding with ‘idna’ codec failed "

From the error pint out, I suspect that channels may have issue to handle very LONG DATABASE_URL, because the DATABASE_URL in Heroku is very LONG, like: postgres://abcdefgijjldfadslfas:12345678901234567890123456789012345678901234567890123456789012345678901234567890@ec2-11-11-11-11-111.compute-1.amazonaws.com:5432/abcdefg12344567 Running successfully in local because local DATABASE_URL is SHORT, like postgresql://postgres@postgres/postgres

  • Your OS and runtime environment, and browser if applicable Heroku, py3.6

  • The versions of Channels, Daphne, Django, Twisted, and your ASGI backend (channels_redis normally)

aioredis==1.0.0
arrow==0.12.1
asgiref==2.2.0
async-timeout==2.0.1
attrs==17.4.0
autobahn==18.3.1
Automat==0.6.0
binaryornot==0.4.4
certifi==2018.1.18
channels==2.0.2
channels-redis==2.1.1
chardet==3.0.4
click==6.7
constantly==15.1.0
cookiecutter==1.6.0
daphne==2.1.0
dj-database-url==0.5.0
Django==2.0.4
django-environ==0.4.4
django-heroku==0.3.1
future==0.16.0
hiredis==0.2.0
hyperlink==18.0.0
idna==2.6
incremental==17.5.0
Jinja2==2.10
jinja2-time==0.2.0
MarkupSafe==1.0
msgpack==0.5.6
poyo==0.4.1
psycopg2==2.7.4
python-dateutil==2.7.0
pytz==2018.3
requests==2.18.4
six==1.11.0
Twisted==17.9.0
txaio==2.9.0
urllib3==1.22
whichcraft==0.4.1
whitenoise==3.3.1
zope.interface==4.4.3
  • What you expected to happen vs. what actually happened Depoly on Heroku should working as local

  • How you’re running Channels (runserver? daphne/runworker? Nginx/Apache in front?) Procfile: web: daphne -b 0.0.0.0 -p $PORT multichat.asgi:application

  • Console logs and full tracebacks of any errors

2018-04-05T10:51:09.963017+00:00 app[web.1]: [2018/04/05 10:51:09] WebSocket DISCONNECT /chat/stream/ [10.148.31.26:12204]
2018-04-05T10:51:09.963413+00:00 heroku[router]: at=info method=GET path="/chat/stream/" host=dj-.herokuapp.com request_id=24997cac-1ae3-4182-95fb-9fc160fcdbae fwd="23.105.202.100" dyno=web.1 connect=0ms service=1050ms status=101 bytes=145 protocol=https
2018-04-05T10:51:11.911270+00:00 app[web.1]: [2018/04/05 10:51:11] WebSocket HANDSHAKING /chat/stream/ [10.33.239.90:28093]
2018-04-05T10:51:11.921067+00:00 app[web.1]: [2018/04/05 10:51:11] WebSocket CONNECT /chat/stream/ [10.33.239.90:28093]
2018-04-05T10:51:12.737859+00:00 app[web.1]: 2018-04-05 10:51:12,737 - ERROR - server - Exception inside application: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
2018-04-05T10:51:12.737872+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__
2018-04-05T10:51:12.737875+00:00 app[web.1]:     await await_many_dispatch([receive, self.channel_receive], self.dispatch)
2018-04-05T10:51:12.737876+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/channels/utils.py", line 47, in await_many_dispatch
2018-04-05T10:51:12.737878+00:00 app[web.1]:     result = task.result()
2018-04-05T10:51:12.737880+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/channels_redis/core.py", line 185, in receive
2018-04-05T10:51:12.737882+00:00 app[web.1]:     self.receive_loop_task.result()
2018-04-05T10:51:12.737884+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/channels_redis/core.py", line 204, in receive_loop
2018-04-05T10:51:12.737885+00:00 app[web.1]:     real_channel, message = await self.receive_single(general_channel)
2018-04-05T10:51:12.737887+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/channels_redis/core.py", line 220, in receive_single
2018-04-05T10:51:12.737889+00:00 app[web.1]:     async with self.connection(index) as connection:
2018-04-05T10:51:12.737890+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/channels_redis/core.py", line 399, in __aenter__
2018-04-05T10:51:12.737892+00:00 app[web.1]:     self.conn = await aioredis.create_redis(**self.kwargs)
2018-04-05T10:51:12.737893+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/aioredis/commands/__init__.py", line 174, in create_redis
2018-04-05T10:51:12.737895+00:00 app[web.1]:     loop=loop)
2018-04-05T10:51:12.737897+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/aioredis/connection.py", line 107, in create_connection
2018-04-05T10:51:12.737899+00:00 app[web.1]:     timeout, loop=loop)
2018-04-05T10:51:12.737900+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/asyncio/tasks.py", line 333, in wait_for
2018-04-05T10:51:12.737902+00:00 app[web.1]:     return (yield from fut)
2018-04-05T10:51:12.737903+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/aioredis/stream.py", line 19, in open_connection
2018-04-05T10:51:12.737905+00:00 app[web.1]:     lambda: protocol, host, port, **kwds)
2018-04-05T10:51:12.737907+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 732, in create_connection
2018-04-05T10:51:12.737908+00:00 app[web.1]:     infos = f1.result()
2018-04-05T10:51:12.737910+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/concurrent/futures/thread.py", line 55, in run
2018-04-05T10:51:12.737911+00:00 app[web.1]:     result = self.fn(*self.args, **self.kwargs)
2018-04-05T10:51:12.737913+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/socket.py", line 743, in getaddrinfo
2018-04-05T10:51:12.737915+00:00 app[web.1]:     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
2018-04-05T10:51:12.737922+00:00 app[web.1]:   encoding with 'idna' codec failed (UnicodeError: label empty or too long)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kevinqqnjcommented, Apr 8, 2018

Thanks @andrewgodwin & @matthiask ! You’re right, REDIS URL is wrong in my settings.py.

Sorry, I blindly followed the tutorial of Channels. Actually if deploying to VPS (e.g. Heroku) other than localhost, should update CHANNEL_LAYERS from Tuple to String, to include username and password:

# settings.py
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            # in tutorial it says: "hosts": [('127.0.0.1', 6379)],
            "hosts": [os.environ.get('REDIS_URL', 'redis://redis:6379')],
        },
    },
}

Now it’s working.

0reactions
iMericacommented, May 22, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

encoding with 'idna' codec failed (UnicodeError: label empty ...
It seems this is an issue from the socket module. It fails when the URL exceeds 64 characters. This is still an open...
Read more >
encoding with 'idna' codec failed (UnicodeError: label empty or...
Description of problem: Boot from Live Fedora 23 USB stick. Attempt to install to disk. During the probe of storage devices, an error...
Read more >
[DARIJA LANG] encoding with 'idna' codec failed (UnicodeError
encoding with ' idna ' codec failed ( UnicodeError : label empty or too long ) python 3.8Django 3.0.7Solution ...
Read more >
encoding with 'idna' codec failed (UnicodeError: label empty ...
I installed anki app on windows 2.1.37-windows for the very first time on Windows 10 19042.685 but it displays the following:
Read more >
codecs should raise specific UnicodeDecodeError ...
... line 1, in <module> UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long) → I was expecting that this ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found