Skip to content

Instantly share code, notes, and snippets.

@pydanny
Last active December 12, 2018 12:31
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pydanny/50c6ef333cbdc8c1a0cc5cedd176bc04 to your computer and use it in GitHub Desktop.
Save pydanny/50c6ef333cbdc8c1a0cc5cedd176bc04 to your computer and use it in GitHub Desktop.
running local unverified SSL on Django and Flask (don't do this in production!!!)
from .common import * # noqa
DEBUG = True
INSTALLED_APPS += ('django_extensions',)
# Snip all the other stuff
"""Old-Skool Flask setup. Yes, I loathe the 'FLASK RUN' pattern as it feels like a
needless abstraction.
"""
from flask import Flask
app = Flask(__name__)
app.secret_key = "This is my secret key."
if __name__ == "__main__":
# This only runs locally when run as "python main.py"
os.environ['DEBUG'] = "1"
# This runs Flask locally with a self-signed SSL certificate.
app.run(debug=True, ssl_context='adhoc')
# Django local unverified SSL requirements
Django (at least Django 1.11)
django-extensions
# You may not need all the below security requirements:
cryptography
certifi
pycparser
asn1crypto
pyOpenSSL
# Flask local unverified SSL requirements
flask
# The security requirement probably installs the same requirements
# as what I use in Django. Haven't checked. Anyway, this works so I'm happy.
requests[security]
# to run Django locally with unverified SSL cert
(python36env) $ ./manage.py runserver_plus --cert /tmp/cert
# to run Flask locall with adhoc SSL cert
(python36env) $ python main.py
@pydanny
Copy link
Author

pydanny commented Jan 4, 2018

This is how we run our core Django service and Flask microservices locally. We do this because OAuthlib and other tools insist on SSL. This is unverified SSL, so it won't work in production. However, it gives us an easy out for running locally in SSL.

Note: We (me and @audreyr) figured this out by delving into documentation and some Stack Overflow. I can't remember where we found these techniques. So no attribution for this gist, just sharing of knowledge.

If we get our APIstar microservice launched (a big "if" there), then I'll post how we got SSL working there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment