Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Websocket connection failed & Not Found: /ws/home/room

new to django-channels and websockets in python and have been struggling with a big project, I can't figure out why I keep getting the errors in the title I even created a new project and followed a youtube tutorial step by step and still get the error

\- the main difference between mine and his is that my user flow goes through three pages -> login to home to the room- I also didn't initialize a virtual environment for my django project (don't think that matters)

from inspection i get websocket connection not found 'ws:// {localhost}/ws/home/room' and from project console i get Not Found: /ws/home/roomI'm trying to learn as I go about websockets and everything but have been struggling with this issue for a while now (a couple days lol)

heres my code:

[urls.py](https://urls.py)

`urlpatterns = [path('', views.login, name='login'),path('home/', views.home, name='home'),path('home/<str:room_name>/', views.room, name='room'),]`

[routing.py](https://routing.py)

`websocket_urlpatterns = [re_path(r'^ws/home/(?P<room_name>\w+)/$', consumers.GameConsumer),]`

[consumers.py](https://consumers.py)

`class GameConsumer(AsyncWebsocketConsumer):def __init__(self, *args, **kwargs):super().__init__(args, kwargs)self.room_name = Noneself.room_group_name = Noneasync def connect(self):self.room_name = self.scope['url_route']['kwargs']['room_name']self.room_group_name = '_%s' % self.room_name # unsure about 'game_%s'''' create new group '''await self.channel_layer.group_add(self.room_group_name,self.channel_name,)`

`await self.accept()`

`await self.channel_layer.group_send(self.room_group_name,{'type': 'tester_message','tester': 'hello world',})`

`async def tester_message(self, event):tester = event['tester']`

`await self.send(text_data=json.dumps({'tester': tester}))`

`async def disconnect(self, close_code):await self.channel_layer.group_discard(self.room_group_name,self.channel_name,)`

and heres where i create the websocket connection

`{{ room_name|json_script:"room-name" }}<script>const roomName = JSON.parse(document.getElementById('room-name').textContent)const socket = new WebSocket('ws://' +window.location.host

/r/djangolearning
https://redd.it/12r4wnx
Astral, the company behind Ruff

https://astral.sh/blog/announcing-astral-the-company-behind-ruff

I am not Charlie Marsh, so this isn't my blog. But I found the premise and the news very interesting and exciting!

ruff has become a can't-live-without tool very quickly, and I'm excited to see what comes out of Astral next

/r/Python
https://redd.it/12r7oi0
Handling Security of Encrypted Data

I want to make an application that is related to crypto. The user would enter a password, that would decrypt a crypto wallet key that is stored in a SQL database, and allow them to use this wallet to run transactions.

I do not want them to enter it for every action, I want to store the decrypted wallet key/the password (ill refer to either as the key) somewhere so it is a smooth interaction. I am curious about the security ethics around this. Where would I store the key, in browser cookies on the client side? If so, how secure is this, and how secure is sending the key back and forth via POSTS to the backend server?

/r/flask
https://redd.it/12r96bd
Dockerized Django with Postgres, Gunicorn, and Traefik (with Let's Encrypt)

Hey fellow Django enthusiasts!

I've created a cool project template that you can use as a foundation for your future projects by simply copying it: https://github.com/amerkurev/django-docker-template

The main idea is to solve all deployment-related issues at the initial stage. In this project, everything is built in Docker, launched with Docker Compose, and Let's Encrypt certificate is automatically issued (you just need to have a domain). The certificate is also automatically renewed. It is configured through environment variables and described how to work in development mode and how to deploy to production.

But the most important thing is the minimalism of this project. It has nothing extra, it's easy to extend or modify.

Personally, I now use it everywhere I need to quickly deploy a Django website. And it only takes me a couple of minutes to deploy everything in the cloud. Then I just write my Django applications.

&#x200B;

I would be very happy if you want to support the project with a PR, an interesting idea, or find bugs and write about it in the issue. Or at least give the project a star :)

I really love Django and value the Django community because it's a really cool product and cool people!

/r/django
https://redd.it/12r59gh
Sample flash app can't be accessed by other device in the local network with host="0.0.0.0" & turned off firewall

I created a simple flash app as followings ...

\---------------

from flask import Flask
app = Flask(__name__)


@ app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":

app.run(host="0.0.0.0")

\---------------

Running the same flask app on both Windows machine#1 (M1) and Windows Machine#2 (M2). M2 can access to M1. No issue. However, the other way around didn't work.

\-- M2 is running flask app with host="0.0.0.0." and turned off firewall from McAfee

\-- M1 can't access the M2 flask app by ip address (192.168.0.111)

\>>> http://192.168.0.111:5000

Any ideas how to troubleshoot this?

/r/flask
https://redd.it/12r6eao
Chili - serialize/deserialize anything from/to dict/json

Hi Python enthusiasts!
I'm thrilled to announce the launch of Chili 2.0, a major update to my object serialization and deserialization library with JSON support. After 2 years of development, I'm excited to share this new version with the Python community.

Chili is a Python library that makes it easy to serialize and deserialize any Python object to and from dict and/or JSON.

I encourage you to check out the GitHub repository to learn more about what's new in Chili 2.0. You'll find detailed documentation, examples, and installation instructions under the following link:
http://github.com/kodemore/chili


How it is different than pydantic? Chili is not a validation library, although it ensures type consistency. This gives it a huge perfomance advantage + easy interface with zero learning curve if you are already familiar with type annotations available in python.


And if you have any questions or feedback, please don't hesitate to reach out. I'd love to hear from you!

/r/Python
https://redd.it/12rkgoc
Best way to organize Django Channels code?

In Django, I usually create a file called a "services" file. The entire business logic sits in this services file. Whenever a request comes the flow will be "urls.py -> views.py -> services.py". My views.py just calls the services.py file and it also handles the exceptions that I throw from the service function.

I've been exploring Django Channels for the last few days and I'm trying to build a chat app. Here I have a consumers.py file and I put the entire chat logic in the class "ChatConsumer". I don't know if this is the best approach. Most of the Django Channels tutorials and examples are just putting the entire logic in one class. What's the best way to organize the code?

I'm thinking of using a services file here as well and then move the entire logic to the services file. Not sure if this is the best approach. Please suggest a good way to organize the Django Channels code.

/r/django
https://redd.it/12ri12u
Jupyter Notebooks 7 Migration Plan

Hi Jupyter family, I would like to migrate over to Jupyter Notebook v7 as detailed in their migration plan (https://jupyter-notebook.readthedocs.io/en/latest/migrate\_to\_notebook7.html). Not going to lie, I have a degree in CS and I still do not understand what I need to do in-order to get jupyter-notebook 7 up and running in my 'data-science' env. The guide is both verbose and overly complicated (opinion) for simple folk like me. Can someone please ELI5 how to install it and get it up and running please?

/r/JupyterNotebooks
https://redd.it/12s3von
In DRF do you validate your query params, if so how?

I know "how?" part bit generic question but let's say you have an student & school API and depending on the uuid you are doing some filtering which directly goes to ORM and if the query param is not valid UUID API will give 500.

However, I also don't recognize query params being validated much, especially like serializers.


I have to validate it but I also don't know what would be the best practices to achieve this?

/r/django
https://redd.it/12rspek
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!

This thread is not for recruitment, please see r/PythonJobs or the thread in the sidebar for that.

/r/Python
https://redd.it/12sf4mb
editair webapp

Hey! I was playing around with flask for a backend API and built a webapp that converts long form videos into short form sharable content. I linked the demo below. If this is something that could be useful to you or someone you know, sign up for the beta and let me know via DM or tyler@editair.app

editair webapp

demo video


If it is a project you think you could help on the dev side, also let me know!

/r/flask
https://redd.it/12sdzzy
Software engineering with Python?

I have been self-studying python for a little bit over a month. I don't exactly wanna go into data analyst/data science/ data engineering, etc. my goal is to become a software engineer/developer (maybe something to do with backend). did I choose the wrong language?

EDIT: @ evryone fucking love you guys. I was so damn confused this morning when i posted this, the 52 comments cleared up so many things you have no idea. I haven't even finished digesting all the information but that clears up so much!!

/r/Python
https://redd.it/12rsedi
Having issues with multiple SQL queries in my app

So I have an app I am working on. Its a simple idea where you register, tell it what streaming services you subscribe to. It then shows you the movies available on those platforms and you can like the movie to add to a watchlist or dislike it to ignore the movie. I have the list of movies in my own DB.

I have the basics of user registration, login, dashboard and logout working. My issue now is the main function. I need to read the users subscriptions from the Users table, show the titles that are on that provider, drawn from a table called StreamingTitles, and then when they click like add the movies id into a liked_titles column in the users table. It's the manipulation of the different tables that are tripping me up and chatgpt isn't being very helpful.

I think I am trying to achieve this in a logical manner. I will end up with a table of users with all their wishlists held as an array which I can manipulate later on. Does it make sense to do it this way?

Database structure:

https://imgur.com/a/lla70ED

&#x200B;

As it's Flask I have used a Jinja2 template structure, and again it's working fine. I

/r/flask
https://redd.it/12spwiz
Just made a python script to post to Mastodon

Just made a python script that allows you to update your status (i.e. make a post on Mastodon). The script allows you to upload an image to your post as well. Hopefully yall think this is useful:
https://github.com/rfrlcode/Public/blob/main/mastodon.py

/r/Python
https://redd.it/12sbxlt
N Stability AI announce their open-source language model, StableLM

Repo: https://github.com/stability-AI/stableLM/

Excerpt from the Discord announcement:

> We’re incredibly excited to announce the launch of StableLM-Alpha; a nice and sparkly newly released open-sourced language model! Developers, researchers, and curious hobbyists alike can freely inspect, use, and adapt our StableLM base models for commercial and or research purposes! Excited yet?
>
> Let’s talk about parameters! The Alpha version of the model is available in 3 billion and 7 billion parameters, with 15 billion to 65 billion parameter models to follow. StableLM is trained on a new experimental dataset built on “The Pile” from EleutherAI (a 825GiB diverse, open source language modeling data set that consists of 22 smaller, high quality datasets combined together!) The richness of this dataset gives StableLM surprisingly high performance in conversational and coding tasks, despite its small size of 3-7 billion parameters.

/r/MachineLearning
https://redd.it/12rxtjj
RE: If you had to pick a library from another language (Rust, JS, etc.) that isn’t currently available in Python and have it instantly converted into Python for you to use, what would it be?

Re u/Tymbl's post.
I implemented Rust's Option and Result types in Python because the amount of times I write code that works straight away is embarrassing when I write Python.
https://github.com/gum-tech/flusso


However, my first feedback was: "It's not Pythonic".
I thought Python is a multi-paradigm programming language. If so, what makes a code Pythonic?

/r/Python
https://redd.it/12sv2m8