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.

Exception inside application: object.__init__() takes exactly one argument (the instance to initialize)

See original GitHub issue

In Channels version 3.0.0 python raise exception when I try connect by websocket to my Django Application . Console log from runserver:

November 01, 2020 - 13:18:04
Django version 3.1.2, using settings 'Menu.settings'
Starting ASGI/Channels version 3.0.0 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
WebSocket HANDSHAKING /ws/dist [127.0.0.1:56024]
Exception inside application: object.__init__() takes exactly one argument (the instance to initialize)
Traceback (most recent call last):
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/channels/routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/channels/sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/channels/sessions.py", line 172, in __call__
    return await self.inner(self.scope, receive, self.send)
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/channels/auth.py", line 181, in __call__
    return await super().__call__(scope, receive, send)
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/channels/middleware.py", line 26, in __call__
    return await self.inner(scope, receive, send)
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/channels/routing.py", line 150, in __call__
    return await application(
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/asgiref/compatibility.py", line 33, in new_application
    instance = application(scope)
  File "/home/nakmak98/source/Menu/pycharm_venv/lib/python3.8/site-packages/channels/generic/websocket.py", line 23, in __init__
    super().__init__(*args, **kwargs)

My code:

index.js var ws = new WebSocket( 'ws://' + window.location.host + '/ws/dist')

routing.py

from django.urls import path

from . import consumers

websocket_urlpatterns = [
    path('ws/dist', consumers.MealPointConsumer),
]

When I run my code on previous version of Channels, it works great.

Django version 3.1.2, using settings 'Menu.settings'
Starting ASGI/Channels version 2.4.0 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
HTTP GET /dist/ 200 [0.14, 127.0.0.1:55192]
...
WebSocket HANDSHAKING /ws/dist [127.0.0.1:55196]
WebSocket CONNECT /ws/dist [127.0.0.1:55196]

My OS: Linux Mint 19.3 pip freeze output:

aioredis==1.3.1
asgiref==3.2.10
async-timeout==3.0.1
attrs==20.2.0
autobahn==20.7.1
Automat==20.2.0
cffi==1.14.3
channels==3.0.0
channels-redis==3.2.0
constantly==15.1.0
cryptography==3.2.1
daphne==3.0.0
Django==3.1.2
hiredis==1.1.0
hyperlink==20.0.1
idna==2.10
incremental==17.5.0
msgpack==1.0.0
Pillow==8.0.1
pkg-resources==0.0.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
PyHamcrest==2.0.2
pyOpenSSL==19.1.0
pytz==2020.1
service-identity==18.1.0
six==1.15.0
sqlparse==0.4.1
Twisted==20.3.0
txaio==20.4.1
zope.interface==5.1.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

70reactions
carltongibsoncommented, Nov 1, 2020

v3 is a big update to ASGI v3, which changes the signuature of consumers.

path('ws/dist', consumers.MealPointConsumer),

Here you need to add the new as_asgi() call when routing your consumer.

See the 3.0 release notes for more details and guidance on updating: https://channels.readthedocs.io/en/stable/releases/3.0.0.html#update-to-asgi-3

You should also probably review the docs, and update to routing.py to asgi.py as you go, to fall in-line with Django’s conventions.

I’ll leave this open for the now in case others bump into similar issues.

That release notes link again: https://channels.readthedocs.io/en/stable/releases/3.0.0.html#update-to-asgi-3

4reactions
jihoon796commented, Jan 13, 2021

@carltongibson it took forever to find your comment, but adding as_asgi() saved me a lot of time. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - TypeError: object.__init__() takes exactly one ...
OK, so the error is actually not in your super(Grid1,self).__init__(**kwargs) statement, it's in the creation of the Submit button. You did:
Read more >
"TypeError: object.__init__() takes exactly one argument (the ...
Python Crash Course inheritance: "TypeError: object.__init__() takes exactly one argument (the instance to initialize)".
Read more >
object.__init__() takes exactly one argument' (Python ... - Quora
The __init__ method has special meaning in Python. It is called immediately after a new object has been created and is used to...
Read more >
Object.__init__() takes exactly one argument (the ... - Panda3D
object.init() takes exactly one argument (the instance to initialize) File “D:\Visual Studio Code\GameObject.py”, line 77, in init “player”)
Read more >
TypeError: __init__() takes exactly 1 argument (2 given)
Getting the error on the line where I try to create the milton instance: class Employee(object): “””Models real-life employees!””” def init(self ...
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