python - cURL 请求拒绝连接 Flask 服务器
问题描述
我有一个简单的 Flask 服务器:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
当我$ curl http://127.0.0.1:5000/
在命令行上运行时,我得到了错误
curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
问题是什么?
解决方案
If the code snippet above is exactly the same to your code that you are trying to run then you are missing app.run()
statement: Also You can specify any port number with port=<port_number>
parameter in app.run()
Try this:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(debug=True)
and then run this script
推荐阅读
- r - 基于 R 的 Power 9 CPU 工作(ppc64le 架构)?
- javascript - 基于变量加载一对图像
- polymer - 将 @Polymer/app-storage 与 lit-element 一起使用
- python-3.x - 实现一个python类
- web-scraping - Scraping - 查找所有子类的名称
- azure - Azure 区块链服务 - 如何向/从事务节点写入和读取?
- terminal - iTerm2:当 PS1 提示的路径太长时,不同行上的路径会损坏(\n)
- python - 如何在 Spyder 4 上隐藏悬停工具提示
- python - LSQ 子问题错误中的奇异矩阵 C - 多个配方
- c++-winrt - 是否在 http://schemas.microsoft.com/winfx/2006/xaml 中绑定 XamlType?