i guess Im randomly asking but does anybody know of a tool to log back into an instagram account? I was dumb forgot my password. I would love any help you can give me!
Thanks for making good content. For the people following along the notebook is referring to websocket-client package. Also the use ws = websocket.create_connection('ws://localhost:8000/ws/polData/') to connect from ipnyb. Also I would recommend author to use requirements.txt files to using pip freeze to make it easier for people to follow the course
Apparently for python versions greater than 3.6 they recommend adding .as_asgi to the url routing. websocket_urlPattern=[ path('ws/polData/',consumer.DashConsumer.as_asgi()), ] using the adjustment to the url and the following in the client code I was able to establish a connection ws = websocket.WebSocket(sslopt={"check_hostname": False}) ws.connect("ws://localhost:8000/ws/polData/") Thanks John
I have now got a good understanding how django channels work. Thank you for the perfect content. Please can you make a video about how to use it to fetch data from database. Much love🥰❤❤❤
awesome tutorial ...i request you to make tutorial on how many users click the link, their ip address,i mean tracking their activities in graph from in backend side of blog website?
Dude totally underrated video. You did such a great job of explaining the theory and implementation of this thank you. I am definitely subscribing and will be eagerly waiting for new videos. Btw as a windows user I ran into a few issues. Below are the solutions that helped: Issue 1: When installing channels (pip install channels) I kept getting an error when it attempted to install Twisted Solution: Use Python 3.7 instead of 3.8, twisted is not supported on 3.8 Issue 2: aioredis.errors.ReplyError: ERR unknown command 'BZPOPMIN', this happens because redis is not supported on windows Solution: Install the Ubuntu 20 app in the windows store and activate the WSL. When you run the app update+upgrade your repos (sudo apt update; sudo apt upgrade -y) then install redis-server and redis-cli (sudo apt install redis-server -y; sudo apt install redis-cli -y) this should install redis version 5. type the command, redis-server to start redis then you shouldnt be good to run django and publish data. I hope this helps.
Hey man , I had this twisted problem before , for python 3.8 u need to download twisted urself for python 3.8 and then install it locally with pip in your project ,at least that's what I did , I'd like to know if u came up with a better solution. and for the redis you could use docker it's very easy u just start a redis server. good luck :) I hope this helps a little
@@ashkanoliaie6548 I've tried many solutions like using WSL 2, installing an older version of redis and using docker on my windows machine to use redis and have not been able to shake the BZPOPMIN error. I've gotten the redis server running in a bunch of different ways but am yet to successfully connect. Does anyone have an explicit basic step-by-step solution on how to run and connect to a redis server in windows? I'm sure I'm missing something simple, docker seems to be easy enough but I just keep getting this error. Thanks in advance
@@technologyfornoobs If I will implement the system in IoT, some architectures involve broker (redis) and worker (celery), why is that? Here you show, the django channel can solve this problem. Then what about the role of the MQTT broker (mosquitto)? can redis replace it? Maybe you can help explain it. Regards
@@doditsuprianto4304 I am not an expert in IoT infra kinds of stuff, yes Redis is still needed in our implementation as well for obvious reasons, and WebSockets is another protocol and MQTT is a diff protocol, where the data packet is even smaller than what we have done in WebSockets.
If you're on Windows and you have problems installing channels with an error like: Microsoft Visual C++ 14 is required, Download Twisted from www.lfd.uci.edu/~gohlke/pythonlibs/#twisted. Choose the win32 one corresponding to your python version. For instance, I used Python 3.8; so I downloaded Twisted‑20.3.0‑cp38‑cp38‑win32.whl (Notice "cp38"). Once downloaded, navigate to the download folder in your command prompt and run 'pip install ' followed by the file u just downloaded. After this you can install channels or whatever. You're welcome!
@@dnj86 Scaling is a different beast, what I did was a PoC where people with few resources or a single resource are just trying to get something in action. to showcase, if a scalale solution needs to be built, another tech stack needs to be introduced. Not just python In my opinion.
Very nice tutorial. I am facing a problem of ws=websocket.WebSocket().It is throwing an error of -__init__() missing 3 required positional arguments: 'environ', 'socket', and 'rfile'
Great tutorial! How can I send data from a server to a ML algorithm in Django that then process it and send the data to a real time graph? Any suggestion? Thanks!
Thank You, I've been understanding really well, but at 38:52, after trying to connect the subscriber to the server I get: in main async def queue_factory() -> asyncio.Queue[str]: TypeError: 'type' object is not subscriptable , please help!
@@technologyfornoobs Now after installing websocket-client it says: No module named websocket.__main__; 'websocket' is a package and cannot be directly executed
Actually i am making web app for my final year project. can you tell me how can i open socket for each edge device, like in my project there will be edge device for each individual client and graph should only be plot for client who logged in into the system.
I would recommend you to go through the concepts again, may be you already know the answer, and also the video is quite old now, many things have change and many other technologies are available to do such things.
@@technologyfornoobs i just want token authentication for user authentication.Each edge device have unique token so that data sending from user edge device must display on their own homepage. if you have discord then we can chat there.
Great tutorial. I have a use case of creating a real time dashboard by fetching continuous data points from a websocket API exposed by a third party app. How do I establish a ws connection with that API using channels?
@@technologyfornoobs I want the real time data points to be stored in the database as well. The architecture I thought of is similar to what you have demonstrated here. Is there a way to run the process of Jupyter notebook in the Django app itself, as a continuous background task or something?
Yes you can, in my video I kept the channel value as constant, you can also pass channel value as dynamic and accordingly websocket will send data and our server will update based on the channel the data belongs.
Thanks, sir for this amazing tutorial. I have a requirement where instead of a dashboard, there will be a table. And data in that table should update automatically when new data is added in DB and that is without refreshing the page. Can we use Channel in that case?
@@technologyfornoobs Thanks for the reply. I was able to upload it to cloud. The roadblock was that Google App Engine doesn't support websockets, so I ended up using Google Compute Engine. I have a follow up questions. If you have multiple windows on a page all streaming, how do you extend the code?
do you mean multiple graphs? or just browser windows?, if multiple graphs, just make an addition in the consumer.py where I have fixed the channel name make it dynamic by sending it as a url parameter and do the required changes in the respective codes.
I looked into consumer.py as you mentioned and created two classes and routed each websocket to different class. It has worked! Thanks for the suggestion.
Hi , i need to do a time series analysis of stock data. Where as i have to show live data graph on frontend ? How can u perform using lstm algorithm to show data and prediction on ui in django?
that could be simple and could be complicated.what's your input structure for LSTM would define the complication in approach, as in real time you will get a single data point, and LSTM would need some window of data to process and predict. but just a clue in Consumer.py file >> receive part you would have the logic to predict.
@@technologyfornoobs thankyou for solution . I appreciate. Can you please tell me more about it. Like how can i exactly use realtime time series analysis of stock data. As of now i only have data in csv where as i could use the same in db and fetch in dashboard but when it comes to real time analysis, it really become hard.
@@storememory I think you need something more robust that this. There are dedicated tools for this problem e.g time series databases like KDB. if you want to have a crude implementation think about using a redis solution with a siding window and performing the calculation there using a pub sub mechanism. UI framework like django and channels are really not the place where business logic and critical processing should happen
Great Content but how did you connect the websocket server from jupyter notebook since i keep getting this error: ws=websocket.WebSocket() TypeError: __init__() missing 3 required positional arguments: 'environ', 'socket', and 'rfile'
I have little confusion about it that We can can send data from client(publisher) to server without redis,then why we have use redis server here? I run this code without redis but I see that it can perfectly send data to server. Hopefully you will reply and help me to know about it. Thanks
We have defined the redis server config in settings if you notice, redis helps on this communication. Django also provides a default server for websocket but it's not recommended to use. Just another point, server is using the redis not client
Great work brother It solved major portion of my problem and helped me to design my code flow. But i am confused about channel layer, and redis. Do we have to run redis on another server in production?? And can you please make a video or deployment?
@@technologyfornoobs Hey hope you're doing good, do you know any free resoucre where i can deploy my django-channels applicaiton free/without credit card
I am getting an error on the ws=websocket.WebSocket. Follow the error msg: "TypeError: __init__() missing 3 required positional arguments: 'environ', 'socket', and 'rfile'". Any idea what is wrong?
@@technologyfornoobs I found the issue. I installed websocket instead of websocket-client. Thanks for answering. Then later in the video, I also had to install websocket. It would be easier if I had follow your requirements.txt. I also had problems with the newer version of channels_redis(as I am on windows). Then I had to specify the correct channels_redis version to install. Now it is working.
Setting up Django environment is a real challenge, several package dependencies. Though there is online support and forums to help but it is gets outdated within dates with new updated packages.
we need consumer for creating the webserver which can publish the data real-time to other consumers if you already have a WebSocket somewhere else you do not need Django component
Great tutorial! When I tried to do Websockers connect, I got this error: ... WebSocket HANDSHAKING /ws/polData/ [127.0.0.1:64222] WebSocket CONNECT /ws/polData/ [127.0.0.1:64222] Exception inside application: ERR unknown command 'BZPOPMIN' ... aioredis.errors.ReplyError: ERR unknown command 'BZPOPMIN' WebSocket DISCONNECT /ws/polData/ [127.0.0.1:64222] Any idea to address the error?
----> 1 ws=websocket.WebSocket() TypeError: __init__() missing 3 required positional arguments: 'environ', 'socket', and 'rfile' got this error and i didnt find the requirements.txt in the git
i m using django 3..there is already asgi.py..TypeError: object.__init__() takes exactly one argument (the instance to initialize) WebSocket DISCONNECT /ws/polData/ [127.0.0.1:57510]
Yes, you are using latest Django which gets you asgi.py file created. And I somehow do not have req.txt file missing in mostly all repositories, not sure why, But for now the error you have is not in django, but in Notebook I am assuming, and the solution for this is you need to install "websocket-client" not the "websocket" only. Try this
Nice tutorial..!! Can you please explain how we can integrate celery with this project. As I am new to django I dont know how to do it. Specifically , what if I want to request some api for data which is sending to receive in websocket instead of running stand alone script in notebook??? it will be great for me if you suggest. Thank you.
I hope you have gone through this link for celery with django: docs.celeryproject.org/en/stable/django/first-steps-with-django.html You are asking, to call an rest API and then send the response to the websocket and proceed on >>> it is possible, but what would be your logic to call the rest, as websocket works on a concept of event, if event happens then all things initiated, So even in my application in the notebook I created a client which was subscribed to my websocket service and event happened and all process started. In your case you also have to write some client whether it is calling a rest or any data event by any device, but at the end it must be subscribed and push the data to your websocket service.
@@technologyfornoobs Thank you for quick reply.. I have read celery doc and implemented it. Problem I am facing is how can I push data from my task function within same project. Means as in your notebook app we first define websocket and send data with "ws.send(URL)" method. Should I use this way to push data in same project or is there any other method to do that. Sorry for my lack of knowledge. But I want to learn.
@@technologyfornoobs I am seeing another error now. File "test.py", line 8, in ws = websocket.create_connection('ws://localhost:8080/ws/polData/') File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_core.py", line 592, in create_connection websock.connect(url, **options) File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_core.py", line 248, in connect self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options), File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_http.py", line 120, in connect sock = _open_socket(addrinfo_list, options.sockopt, options.timeout) File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_http.py", line 200, in _open_socket raise err File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_http.py", line 175, in _open_socket sock.connect(address) ConnectionRefusedError: [Errno 111] Connection refused
@@technologyfornoobs Using IP of the server in connect request gives a different error. websocket.create_connection('ws://x.4.95.208:8080/ws/polData/') Traceback (most recent call last): File "", line 1, in File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_core.py", line 592, in create_connection websock.connect(url, **options) File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_core.py", line 252, in connect self.handshake_response = handshake(self.sock, *addrs, **options) File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_handshake.py", line 79, in handshake status, resp = _get_resp_headers(sock) File "/home/adtran/.local/lib/python3.8/site-packages/websocket/_handshake.py", line 164, in _get_resp_headers raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers) websocket._exceptions.WebSocketBadStatusException: Handshake status 500 Internal server error ########################### Error on Django Server: Exception inside application: No application configured for scope type 'websocket' Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/channels/routing.py", line 73, in __call__ raise ValueError( ValueError: No application configured for scope type 'websocket' WebSocket DISCONNECT /ws/polData/ [x.4.95.208:43598]
Hello, you need to have both websocket and websocket client in your env, websocket is used in django side, websocket-client is used in notebook to communicate as a 3rd party tool or device.
Thank you for the video. I am trying to develop a django dashboard for sensor data so it is really in line with what I am trying to do. I am getting an error with the Jupyter code. I have installed websocket-client and uninstalled websocket and websockets. The first error I get is ws=websocket.WebSocketApp() TypeError: __init__() missing 1 required positional argument: 'url' If I put the url in ws=websocket.WebSocketApp('ws://localhost:8000/ws/polData/') The following error comes up. ws.connect('ws://localhost:8000/ws/polData/') AttributeError: 'WebSocketApp' object has no attribute 'connect' No Handshake occurs Thoughts appreciated.
bro could you make a recommendation system using tensorflow and integrate the model in a e - commerace type web application of django. please bro... by the ways loved your videos
@@technologyfornoobs at 28:52 from where are you sending data to the routing port. Cause i am receiving error, "no connection made, because target machine actively refused it." which website are you using to generate client side data? How can i generate the same on my system itself? please elaborate
@@technologyfornoobs Ya But I think it is real-time and I want to store the message so that whenever anyone loads the page all the message will be there forever
Hi, I got this issue with websocket connection as it is getting closed due to handshake error , The error Message are as below: WebSocket HANDSHAKING /ws/polData/ [127.0.0.1:59304] Exception inside application: object.__init__() takes exactly one argument (the instance to initialize) Traceback (most recent call last): File "/usr/lib/python3.7/site-packages/channels/routing.py", line 71, in __call__ return await application(scope, receive, send) File "/usr/lib/python3.7/site-packages/channels/sessions.py", line 47, in __call__ return await self.inner(dict(scope, cookies=cookies), receive, send) File "/usr/lib/python3.7/site-packages/channels/sessions.py", line 172, in __call__ return await self.inner(self.scope, receive, self.send) File "/usr/lib/python3.7/site-packages/channels/auth.py", line 181, in __call__ return await super().__call__(scope, receive, send) File "/usr/lib/python3.7/site-packages/channels/middleware.py", line 26, in __call__ return await self.inner(scope, receive, send) File "/usr/lib/python3.7/site-packages/channels/routing.py", line 160, in __call__ send, File "/usr/local/lib/python3.7/dist-packages/asgiref/compatibility.py", line 33, in new_application instance = application(scope) File "/usr/lib/python3.7/site-packages/channels/generic/websocket.py", line 159, in __init__ super().__init__(*args, **kwargs) TypeError: object.__init__() takes exactly one argument (the instance to initialize) WebSocket DISCONNECT /ws/polData/ [127.0.0.1:59304]\
Hey, really amazing content, I was searching for this only. I am working on my own data analysis backend and I have very similar requirement, but the source of data is different and I am stuck on that. I would like to get your insight on same. How can I contact you ? Hope you will reply
works with 3.1, I tried this with 3.1 and definitely works, see my other comment for very minor change you might have to make. Another minor change might be required to use the same with Daphne where you need to get the 'default' application and setup django instead of just the asgi application
Consumers receive the connection’s scope when they are initialized, which contains a lot of the information you’d find on the request object in a Django view. It’s available as self.scope inside the consumer’s methods.
@@technologyfornoobs how to check , second user disconnected or not. I think in websocket _ disconnect function we have to use , self.channels.group_send( Group_name, { Type:'leave.room', message:'leve room'} ) method , am right or not .
yes some thing similar, by this logic you can also add how many user are in the chat room or if any user left the room kind of functionality, as the connection get closed by the user it does reach to disconnect functionality and as I haven't written anything so it does not do any thing.
I can but don't you think it will be over killing and all people will just ping and so all those notorious things will happen like sharing irrelevant contents
@@technologyfornoobs no bro i meant making a chatroom like app where users can create a room and others can join you can also give them the option to make public or private rooms that's what i have to for school but i already know about websockets and channels i just don't know how to create a database for the rooms and allow real time messaging in it
Hi It's a Nice Video. Is it require to have python code on third party sensors. or please let me know how to featch data from sensors to phyton programe . Appreciate if you help me and share your email Id.