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
Invalid HTTPHOST header from Random domains

I have deployed this Django webapp in digital ocean droplet. I have deployed the app nginx, gunicorn, postgress way. I just added Admin mail in my production setting to get error mail, and noticed this error with different random domain request. To be honest I have little bit of experience with Django but very little knowledge about the production. I am getting multiple errors per minute with random unknown domains. Can somebody help?



Invalid HTTP\
HOST header: 'www.earsoccerfusion. org'. You may need to add 'www.earsoccerfusion. org' to ALLOWED_HOSTS.

DisallowedHost at /
Invalid HTTP_HOST header: 'www.earsoccerfusion. org'. You may need to add 'www.earsoccerfusion. org' to ALLOWED_HOSTS.

/r/django
https://redd.it/1cmhcmz
Has anyone made a flask application (and deployed it for free) that deals with ML models?

I want to hear some thoughts on it since I am having trouble finding a free hosting server for a flask application that can deal with h5 files (model files).

/r/flask
https://redd.it/1cmiuya
Rethinking String Encoding: a 37.5% space efficient string encoding than UTF-8 in Apache Fury

In rpc/serialization systems, we often need to send namespace/path/filename/fieldName/packageName/moduleName/className/enumValue string between processes.
Those strings are mostly ascii strings. In order to transfer between processes, we encode such strings using utf-8 encodings. Such encoding will take one byte for every char, which is not space efficient actually.
If we take a deeper look, we will found that most chars are lowercase chars, ., $ and _, which can be expressed in a much smaller range 0\~32. But one byte can represent range 0\~255, the significant bits are wasted, and this cost is not ignorable. In a dynamic serialization framework, such meta will take considerable cost compared to actual data.
So we proposed a new string encoding which we called meta string encoding in Fury. It will encode most chars using 5 bits instead of 8 bits in utf-8 encoding, which can bring 37.5% space cost savings compared to utf-8 encoding.
For string can't be represented by 5 bits, we also proposed encoding using 6 bits which can bring 25% space cost savings

More details can be found our blog https://fury.apache.org/blog/fury_meta_string_37_5_percent_space_efficient_encoding_than_utf8

/r/Python
https://redd.it/1cmcy3y
List of Sites that Packages Need to Connect to?

I'm doing most of my work behind a government firewall, and I'm having trouble connecting to certain sites. I can do the usual "pip" installs just fine, but I'm talking about packages that need to download data to do their job. An example is the NLTK (Natural Language Toolkit) package, which downloads dictionaries, lookup tables for sentiment analysis, and so on. I know what sites to open up for that particular problem (pastebin.com and nltk.org), but I wonder if anybody's made a list of such sites for different packages.

I can ask for the two sites I know about to be opened up, but I'd like to have a more comprehensive list so I don't have to go through the red tape multiple times.

/r/Python
https://redd.it/1cmdfvy
Web App Deployment

I am trying to deploy a full web app, postgres database, Python middleware, react. I made it for my company I wanted to dockerize and deploy using AWS Rws and app runner, my company wants me to use rstudio connect and said this is their “server” what is rstudio connect? Can I accomplish a full deployment using rstudio connect? To me it seems like a server manager and sounds like it will add pointless extra weight.

/r/Python
https://redd.it/1cmmgu9
Wednesday Daily Thread: Beginner questions

# Weekly Thread: Beginner Questions 🐍

Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.

## How it Works:

1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.

## Guidelines:

This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).

## Recommended Resources:

If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.

## Example Questions:

1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?

Let's help each other learn Python! 🌟

/r/Python
https://redd.it/1cmqqgn
Slow App, Cache it?

I made a flask app that’s kinda slow because it does complex database operations. It is what it is. The data doesn’t change all that much, daily fidelity is plenty.

Could I cache return render template somehow as static html for each of the slow routes? Would be much faster to read the data from disk thank dynamically query it

What I am thinking is to maybe have a cronjob to write static html files using a background flask worker and then return literally just the muliline string as response? Hacky approach but should work, no?

Maybe there’s a better way?

/r/flask
https://redd.it/1cmqpc8
Flask app deployment?

At my current internship, I've finished the basics of my service. Right now for testing, its set up as a flask application and is being tested with postman.

I've setup a connection to the company's database through SQLAlchemy which modifies a dynamic stored procedure in order to fetch the specific data. The same procedure processes the data which is then sent through a Prophet model to plot and predict a sickness curve. The datapoints are extracted and saved in a cache local SQLAlchemy database for 24h.

The plan is, once every night, this procedure iterates through each of the combination of parameters (around 160) and saves the data points in the caching db. Then when the user makes a request the answer comes almost instantly.

What is the best way for deployment here? Everything I can find online is just "Hello world" app deployments.

/r/flask
https://redd.it/1cn05hq
When to break a model into smaller models

I am fairly new to Django and was curious about how best to set up a model in my webapp. I'm messing around and trying to build something akin to PCPartPicker. When I started, I just had a model called "Parts" where all the parts were stored. I quickly realized that if I wanted to account for every specification each part might have, the list of fields in the model would be in the hundreds. There are many specs that apply to all parts such as mass, dimensions, and price, but there are many that are only applicable to one part type (e.g. fan speed, or case material).

My question is, are my two options to have either one mega-model or to have 50+ part type specific models, such as a battery model, fan model, processor model, etc. Or is there a middle path that I am not aware of?

A similar but slightly different question I also have is how to account for specs that have a variable number of values - such as part interfaces? One part might just have a single ethernet cable, whereas one part might have 5 RS422 cables, a coax cable, and a power

/r/django
https://redd.it/1cmv427
Webhook reciver callback url

Hi all,
I am creating an application where my application will send a webhook callback URL to 3rd party website on internet when will then send data to this URL when any event happens.

Few questions I have on my mind is,

1. Is there CORS list in flask by default which i would have to overwrite to receive data from 3rd party wensite.

2. How will I send the call back URL to the website i mean in production i could maybe just use url_for("webhookCallback", external=True) but not sure how will I send url in development. For testing

If you have worked with webhook in flask please let me know, I could look at your project.

Please tell your thoughts on this.

/r/flask
https://redd.it/1cmn1kb
How to run python code from Javascript in Jupyterlab

My usecase is to get access and refresh tokens from the browser cookie or local storage using the jupyterlab cell. I have found a way to do this, but it is not working properly. I have followed the following steps

1. Enabled jupyterapp c.LabApp.expose_app_in_browser = True
2. Running the following code to get cookies from the browser

​

from IPython.display import display, Javascript
jscode = """
async function run() {
const session = jupyterapp.shell.currentWidget.context.sessionContext.session;
const kernel = jupyterapp.serviceManager.sessions.
connectToKernel({model: {id: session.kernel.id, name: session.kernel.name}})
const cookies = document.cookie.split(';').reduce((acc, cookie) => {
const name, value = cookie.trim().split('=');
accname = value;
return acc;
}, {});
await kernel.requestExecute({code:
globals()["access"] =
+ '${cookies.access}';
globals()["refresh"] =


/r/JupyterNotebooks
https://redd.it/1cn1zwh
Why is Plotly so cumbersome to tweak?

I made this visualisation with this code.

I have three questions:

1. Is Plotly supposed to be this cumbersome to tweak? Would other libraries require the same amount of code to add the details I did?
2. Can my code be reduced in size? Maybe it's me who is complicating things with Plotly and there are easier ways to do what I am doing.
3. Any R enthusiast who can tell me how much shorter this code would look like with ggplot2? I asked ChatGPT but the result was garbage.

Bonus question: This took me an entire morning. Is it normal to be "that slow" to plot a simple figure?

/r/Python
https://redd.it/1cn01jc
Made Timely - A notebook web app in Django

Hey Django Devs,

As a Student, I enjoy using the OneNote App because it comes preinstalled with the Office Pack, and after using it for 2.5 years I got bored with it and decided to make my own. That's how I created Timely, a user-friendly note-taking solution with All functional features some examples are reminders and easy notebook sharing.

For some fun I have also thought about how to promote it - Are you tired of complex note-taking apps or limited free versions? You can look no further than Timely, a sleek and efficient notebook app designed to make your daily notes without the hassle.

The problem is that I just made this thing so quickly that some features like password reset pages are missing and it has optimization issues when more data is being loaded please tell me how I can improve it. It has a load time of like 7 to 8 seconds straight and I want to minimize it.

I am using Django + halfmoon.css library + FontAwesome Icons(I examined and found out that this is why it is taking a lot of time to load).

🔗 Check it out here: Timely Web App

Preview: Timely | Shared Notebook

I’m eager to hear

/r/django
https://redd.it/1cn0icr
Just Fumbled an Interview today

So yesterday evening a recruiter called and asked my current responsibilities and sent an assesment after shortlisting. I've completed the assessment ASAP and the recruiter got back on WhatsApp after 15 min saying that they wanna schedule interview today itself. I prepared everything in django and DRF. While the interviewer just came with a word doc which has a table Schema and the discussion went from select * from table to cases and joins. The worst part here is I fumbled in joins, cause I even didn't had the time to prepare for SQL. After that he just asked some basic questions in django and ended the interview.

Felt disguised about this, anyways it was a high paying remote opportunity.
And, the JD has Django and DRF highlighted along with SQL.
Annoying part is, I even built a project with CRUD, exploring all variations in Views, serializers, throttling, pagination, auth and permissions in this time span. Which never were asked.

/r/django
https://redd.it/1cna6t6
Who is using quart framework for microservices?

I am using quart framework (https://quart.palletsprojects.com) for a number of microservices in a SaaS application. However, I hardly hear anything about this framework on any social media platform which seems to be dominated by FastAPI. Also I'm unable to find which all projects/companies are using this framework. All this is leading to anxiety around the future of this project.

Are there any well known projects / companies which are using this framework for microservices?

/r/Python
https://redd.it/1cn8zg3
How are you using AI for development?

I just wrote a shell script that copies my models.py, views.py, etc, appends the app name and changes the extension to .txt (example views.py in app users becomes users_views.txt)

These I then upload to chatgtp to ask questions and what not. I pat for chatgpt and dont want to pay additionally for copilot. Maybe I should just pay for copilot instead? 🤔

Anyway, I also wrote a system prompt asking chatgpt so act a senior software dev experienced in django a what not.

So I basically copy paste the prompt, attach the files, then say example "create a user view to do XYZ".

Caveman stuff but it works.

How are you doing it? Everybody using copilot? Myabe the amish way still?

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

# Weekly Thread: Professional Use, Jobs, and Education 🏢

Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.

---

## How it Works:

1. Career Talk: Discuss using Python in your job, or the job market for Python roles.
2. Education Q&A: Ask or answer questions about Python courses, certifications, and educational resources.
3. Workplace Chat: Share your experiences, challenges, or success stories about using Python professionally.

---

## Guidelines:

- This thread is not for recruitment. For job postings, please see r/PythonJobs or the recruitment thread in the sidebar.
- Keep discussions relevant to Python in the professional and educational context.

---

## Example Topics:

1. Career Paths: What kinds of roles are out there for Python developers?
2. Certifications: Are Python certifications worth it?
3. Course Recommendations: Any good advanced Python courses to recommend?
4. Workplace Tools: What Python libraries are indispensable in your professional work?
5. Interview Tips: What types of Python questions are commonly asked in interviews?

---

Let's help each other grow in our careers and education. Happy discussing! 🌟

/r/Python
https://redd.it/1cnjfub
User models

At my work, I have a system that handles several user types but only one user model and the roles relate to a many-to-many table. Today they asked my partner and I to change it and make a user table for each type of user even though they have mostly the same fields. They told us that it is to improve performance but I know that it is bad practice and I wanted opinions that would help me convince the manager not to do it that way. Thank you.

/r/django
https://redd.it/1cnj9mj
The new REPL in Python 3.13.0 beta 1

Python 3.13.0 beta 1 was released today.

The feature I'm most excited about is the new Python REPL.

[Here's a summary of my favorite features in the new REPL along with animated gifs](https://treyhunner.com/2024/05/my-favorite-python-3-dot-13-feature/).

The TLDR:

* Support for block-leveling history and block-level editing
* Pasting code (even with blank lines within it) works as expected now
* Typing `exit` will exit (no more `Use exit() or Ctrl-D (i.e. EOF) to exit` message)

/r/Python
https://redd.it/1cnf0p5
New in person meetup in Denver,CO

This is going to be our first Python frontend - Django meeting. They will be held the first Sunday of the Month starting on June 2nd. We have other meetups that are held by our Python User Group. This first meeting will be more of getting to know what folks want to learn and share.

Join me at Python Frontend & Django Meetup https://meetu.ps/e/N7lG1/4KNmC/i

/r/django
https://redd.it/1cnaryl