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
Need help with Flask API regarding security and JWT

Hello fellows,

​

Long story short, I am developing my API using Flask and I want to secure it against replay attacks and other MITM things, as well as random people querying the address.

​

So I have seen that JWT could be the answer (using secure HTTP of course to prevent those nice MITM) but there is something I definitely can't understand.

​

Once we auth ourself, the server gives us a token, that we are supposed to **store** and send at every request to prove the server we are the real auth person.

But by doing so, considering we send the token using HTTPs so saying like 'okay it's supposed to be enough secure (https) and anyway we won't be querying the api in vulnerable environnement such as public wifi etc..' and considering the token will be linked to a socket right ? Like we link the TOKEN to A USER, for A SESSION therefor the TOKEN is only good for our actual socket (IP/PORT couple), correct me if i'm wrong.

​

So this ensure only *US* at this exact moment can use this token, and not some guy from idk where since that, even if he gets it, he will not have the

/r/flask
https://redd.it/ba7bg1
Python programmers of reddit: what's the most useful tiny little efficiency you've discovered that's improved your programming hugely?

Whether it's default dicts, enumerate, a way to combine functions really efficiently, or whatever, what's the best tiny trick you've discovered that's improved your code massively?

/r/Python
https://redd.it/basnhi
Is what I'm trying to do even possible?

This might sound really stupid but how can I do something like this:

i = 'profile'

return self.user.i

Where the variable "i" is the attribute.

/r/django
https://redd.it/bb246d
Reports (i.e. Crystal) via Python

Does anybody know of any reporting tools that have been developed in Python?

Specifically, what I'm looking for is either a) a way to generate PDFs from a crystal .RPT file or b) an "open" format that could generate something similar fairly "easily" for an end user. I guess I envision something like like a flask or django template, but could then generate a report in PDF format when ran...

We use crystal reports pretty extensively in my organization for both multipage reports (for instance, sales reports) and for reports that are generally single pages (for instance, invoices are usually single page unless there are more than ~10 line items).

I've considered writing a django app (it's what I'm familiar with) to accomplish something like this for myself, but would want to make it so others could also potentially develop their own reports... I've built PDF reports using straight python before, and while that works for me, I can't imagine asking others to write python code to customize their own reports-- and I really want to avoid reinventing the wheel if a product already exists (preferably open-source so it can be incorporated into another open-source project, but if necessary,

/r/Python
https://redd.it/bb3kqk
How to stop caching? Its driving me nuts!

Im using the dev server that comes with Flask. Every time I update CSS or a template, I cant even hard refresh to get the new stuff to show. I have to restart the server. I used this before and it worked months ago, but for some reason its not working with the new web app I am working on.

​

@app.after\_request
def after\_request(response):
response.headers\["Cache-Control"\] = "no-cache, no-store, must-revalidate, public, max-age=0"
response.headers\["Expires"\] = '0'
response.headers\["Pragma"\] = "no-cache"
return response


/r/flask
https://redd.it/ba2zul
[AF] Using WTForms to pass a variable to tweepy python script

Hi,
I've been following the flask tutorial from Miguel Grinberg. currently up to stage 3 following wtforms.

I'm trying to take an input of a user name for a twitter account and then input that into a python script with tweepy and return something like the number of tweets or from said account and display that to an output page.

Everything is working so far and I take a username but how do I then call input that into a second script? and also how do I return this data to output page. I have a separate script that returns the tweepy data into a json file.

The site is up and running with uwsgi and nginx all working correctly so far which is good. Any help would be amazing as I'm pretty new to this and want to experiment but i'm having some difficultly wrapped my head around some concepts when it comes to processing the data and not running everything from a single .py file

ideally I would like something like this page
https://tweetanalyzer.net/

/r/flask
https://redd.it/ba6vb6
Introducing pybrowser !

Hello everybody,

**pybrowser** is an attempt to simplify browser automation designed keeping end user in mind. Here is an example of usage,

from pybrowser import Browser
with Browser(browser_name=Browser.CHROME) as b:
b.goto("https://www.google.com/")
b.input("name:=q").enter("news")
b.button("name:=btnK").click()
b.take_screenshot()
print(b.html().elements.links())

It's a simple API inspired by ruby's watir with selenium and requests under the hood.
This is the first version for public usage (v0.0.1) and hence expect it to be buggy and what not. At this point definitely don't recommend for commercial use. But do play around and have fun !

[Read more...](https://pybrowser.readthedocs.io/en/latest/)

This is also my first API. So welcome any feedback :)

/r/Python
https://redd.it/bb4bdx
Nimoy testing framework - 0.0.1b7

After a long break I've Just released beta 7 of the [Nimoy testing framework](https://github.com/browncoat-ninjas/nimoy)!

This version introduces syntactic sugar for [staging mock responses](https://github.com/browncoat-ninjas/nimoy#pretty-mock-response-staging):

```
class MySpec(Specification):
def my_feature_method(self):
with setup:
the_mock = mock.Mock()
with when:
the_mock.some_method() << [5, 6, 7]
with then:
the_mock.some_method() == 5
the_mock.some_method() == 6
the_mock.some_method() == 7
```

/r/Python
https://redd.it/bb74dc
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/bb8dv4
Database design

Hi guys, so I was wondering if there were any online tool, or your favourite method how to design DB tables/Django Models and relations between them. I seem to have a really hard time when trying to visualize in my head what I need to do to. I am kinda unable to see how to models are going to work together until I test it in the admin interface, only then it makes sense, but it's just highly ineffective and I had to completely wipe out the whole DB and re-do it again many times because I broke something when creating migrations. I never really know, what to set as defaults. I can make a functional DB, but I want to do it well, normalized.

&#x200B;

Maybe even some typical examples would help. Like I know that a foreign key is a column that branches out to rows in another column, but when the table it points to consists of another foreign key, my head is about to explode xD

&#x200B;

For example I am building an eshop but without prices, carts, payments etc. just like a gallery and the rest is discussed with a customer. Now this is what I have so

/r/django
https://redd.it/bb9yos
MLConjug. A Python library to conjugate verbs in French, English, Spanish, Italian, Portuguese and Romanian (more soon) using Machine Learning techniques.

Hi all,

&#x200B;

I am the author of the open source project [mlconjug](https://pypi.org/project/mlconjug/), a Python library to conjugate verbs in French, English, Spanish, Italian, Portuguese and Romanian (more soon) using Machine Learning techniques.

&#x200B;

Any verb in one of the supported language can be conjugated, as the module contains a Machine Learning model of how the verbs behave. Even completely new or made-up verbs can be successfully conjugated in this manner. The supplied pre-trained models are composed of:

* a custom-made binary feature extractor,
* a feature selector using Linear Support Vector Classification,
* a classifier using Stochastic Gradient Descent.

MLConjug uses scikit-learn to implement the Machine Learning algorithms.Users of the library can use any compatible classifiers from scikit-learn to modify and retrain the models.

* Free software: MIT license
* Documentation: [https://mlconjug.readthedocs.io](https://mlconjug.readthedocs.io/).

### Supported Languages

* French
* English
* Spanish
* Italian
* Portuguese
* Romanian

### Features

* Easy to use API.
* Includes pre-trained models with 99% + accuracy in predicting conjugation class of unknown verbs.
* Easily train new models or add new languages.
* Easily integrate MLConjug in your own projects.
* Can be used as a command line tool.

&#x200B;

Do not hesitate to try it out and let me know if you find bugs, want to propose improvements or want some specific languages added.

&#x200B;

Cheers,

&#x200B;

SekouD

/r/Python
https://redd.it/bb8400
Has anyone built a project based on Guardian?

Long story short, I'm working on a project in which I need to be able to assign users to a group and groups to an event. I have read through the guardian documentation and I believe this does exactly that, providing the ability to create unique events with groups over users that can modify them.

This is the first project of this kind that I've worked on, so I'm interested to see if anyone can chime in. Specifically:

1. Did you create an intermediate model to link the group to the event?
2. Should this live in three separate apps: User, Group, Event?

Thanks in advance.

/r/django
https://redd.it/bbbhcm
Django with Graphene

Hey guys,

&#x200B;

I'm creating my first django graphql api with graphene and wondering how can this be written in a shorter way:

&#x200B;

[https://pastebin.com/T4nsEZMj](https://pastebin.com/T4nsEZMj) \- [models.py](https://models.py)

[https://pastebin.com/71Q6KC4q](https://pastebin.com/71Q6KC4q) \- schema.py

&#x200B;

[https://pastebin.com/3Lu7268q](https://pastebin.com/3Lu7268q) \- graphql\_query

[https://pastebin.com/3VQSb3Wy](https://pastebin.com/3VQSb3Wy) \- graphql\_results

/r/django
https://redd.it/bbceyd