A
A
AlmazKayum2022-01-22 15:55:32
Flask
AlmazKayum, 2022-01-22 15:55:32

How to connect an https domain to flask?

The API works on VPS on Python Flask.
Requests go to the IP address from http:// 123.456.123.456/api/ It is
necessary to put a domain with https instead of IP
. To do this, I wrote a code from examples from Google:

from flask import Flask
from flask import jsonify, make_response, request, abort, redirect
from flask_sslify import SSLify
from flask_cors import CORS
import conf

WEBHOOK_HOST = '123.456.123.456'
WEBHOOK_PORT = 80
WEBHOOK_LISTEN = '0.0.0.0'
DATABASE = conf.database

app = Flask(__name__)

context = ('crt.crt', 'key.key')

sslify = SSLify(app)
CORS(app)

@app.route('/', methods=['GET'])
def get_data():
    data = {}
    return jsonify(data)

# Start flask server
app.run(host=WEBHOOK_LISTEN,
        port=WEBHOOK_PORT,
        debug=False,
        ssl_context=context)

The domain and certificate 'crt.crt', 'key.key' are bought on reg ru, record A is configured on my IP.

When requesting a domain through a browser, the error is ERR_CERT_AUTHORITY_INVALID.

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hey_umbrella, 2022-01-25
@hey_umbrella

The easiest way is to simply add --certfile crt.crt --keyfile key.key to flask run

G
Gleb, 2022-01-31
@Hrafnir

I would strongly advise wrapping everything in docker-compose, it's like a world without drugs in development.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question