Flask How to use HTTPS?

Source: Internet
Author: User

1. Install Python's OpenSSL class library

install pyOpenSSL

2 can be used directly in Flask code, note that ssl_context the value must be adhoc

from flask import Flaskapp = Flask(__name__)app.run(‘0.0.0.0‘, debug=True, port=5000, ssl_context=‘adhoc‘)

The above code uses PYOPENSSL to bring your own certificate. If you want to use a certificate of your own configuration, you can configure it yourself and use it.

3 Generate Certificate:

Generate a private key
openssl genrsa -des3 -out server.key 1024

Generate a CSR
openssl req -new -key server.key -out server.csr

Remove Passphrase from key

cp server.key server.key.org 
openssl rsa -in server.key.org -out server.key

Generate Self signed certificate

365 -in server.csr -signkey server.key -out server.crt

Using the configuration certificate, the certificate path is self-modifying

from flask import Flask    app = Flask(__name__)    app.run(‘0.0.0.0‘, debug=True, port=8100, ssl_context=(‘/Users/kracekumarramaraju/certificates/server.crt‘, ‘/Users/kracekumarramaraju/certificates/server.key‘)) 

Reference:

http://blog.csdn.net/shenzhan168/article/details/47783651
Http://kracekumar.com/post/54437887454/ssl-for-flask-local-development

http://flask.pocoo.org/snippets/111/

Http://blog.chinaunix.net/uid-9793706-id-3566191.html

Http://baike.baidu.com/view/5262561.htm

Flask How to use HTTPS?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.