【发布时间】:2021-09-25 22:27:41
【问题描述】:
我正在运行 python 程序,“app.run”指定主机名和端口。 它默认运行在 Http 上,但我想运行在 Https 上。
我该怎么做?
【问题讨论】:
-
什么是“app.run”?请出示minimal reproducible example。
-
您使用的是哪个 Web 应用程序框架?流行的在他们的教程中有关于如何将它们部署到生产环境的部分,然后您可以在其中获得 true HTTPS 支持。
-
如果
app.run是Flask,那么请看:can you add HTTPS functionality to a python flask web server? -
您好,Mempin,感谢您提供详细信息。是的,app.run 是 Flask。根据链接,我尝试了“OpenSSL import SSL”和“import ssl context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)”但失败并显示消息“AttributeError:模块'OpenSSL.SSL'没有属性'PROTOCOL_TLSv1_2'”或“ SyntaxError: 无效语法”。
-
我现在可以使用 "ssl_context='adhoc'" 命令在 https 中运行程序。但是当尝试从另一个服务器/源连接这个程序时,得到响应“HTTP 错误 404。找不到请求的资源。”或“无法访问此站点”,源和目标之间的 telnet 工作正常,因此没有防火墙问题。使用默认 http 协议运行时能够从源连接到程序。
标签: python