Flask – Active Directory Authentication [closed]

It is quite easy to work with Flask as it is a lightweight and plugin-based Python web framework. Things you will need for LDAP Configuration LDAP Host LDAP Domain LDAP Profile Key You need to install Flask-LDAP plugin pip install Flask-LDAP and here is a basic example to get you started: from flask import Flask … Read more

Error 99 connecting to localhost:6379. Cannot assign requested address

In the flask app I have a function that tries to create a redis client db = redis.Redis(host=”localhost”, port=6379, decode_responses=True) When your flask process runs in a container, localhost refers to the network interface of the container itself. It does not resolve to the network interface of your docker host. So you need to replace … Read more

Flask/SQLAlchemy – Difference between association model and association table for many-to-many relationship?

My apologies, I finally stumbled across the answer in the SQLAlchemy docs… https://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html#many-to-many …where they explicitly define the difference: Many to Many adds an association table between two classes. association_table = Table(‘association’, Base.metadata, Column(‘left_id’, Integer, ForeignKey(‘left.id’)), Column(‘right_id’, Integer, ForeignKey(‘right.id’)) ) The association object pattern is a variant on many-to-many: it’s used when your association table … Read more

Testing flask-oauthlib locally without https

From http://requests-oauthlib.readthedocs.org/en/latest/examples/real_world_example.html: You should note that Oauth2 works through SSL layer. If your server is not parametrized to allow HTTPS, the fetch_token method will raise an oauthlib.oauth2.rfc6749.errors.InsecureTransportError . Most people don’t set SSL on their server while testing and that is fine. You can disable this check in two ways: By setting an environment variable. … Read more

sqlalchemy postgresql enum does not create type on db migrate

I decided on this problem using that. I changed the code of migration, and migration looks like this: from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql def upgrade(): banner_status = postgresql.ENUM(‘active’, ‘inactive’, ‘archive’, name=”banner_status”) banner_status.create(op.get_bind()) op.add_column(‘banner’, sa.Column(‘status’, sa.Enum(‘active’, ‘inactive’, ‘archive’, name=”banner_status”), nullable=True)) def downgrade(): op.drop_column(‘banner’, ‘status’) banner_status = postgresql.ENUM(‘active’, ‘inactive’, ‘archive’, … Read more

How do I run a flask app in gunicorn if I used the application factory pattern?

Create a file wsgi.py under your project with the following contents, then point Gunicorn at it. from my_project import create_app app = create_app() gunicorn -w 4 my_project.wsgi:app # -w 4 specifies four worker processes If you’re using the application factory pattern, Gunicorn allows specifying a function call like my_project:create_app(). For most cases, you can the … Read more