ERR_ADDRESS_INVALID,找不到404,本地主机:8000

时间:2020-02-26 02:07:02

标签: python flask localhost

我真的不知道从哪里开始,也不真正知道问题从何而来,这就是为什么我找不到这个问题的确切标题的原因。这是我的问题。

我从github复制了此代码,作为学习API的教程的一部分:

from flask import Flask
app = Flask(__name__)


@app.route('/readHello')
def getRequestHello():
    return "Hi, I got your GET Request!"

@app.route('/createHello', methods = ['POST'])
def postRequestHello():
    return "I see you sent a POST message :-)"


@app.route('/updateHello', methods = ['PUT'])
def updateRequestHello():
    return "Sending Hello on an PUT request!"


@app.route('/deleteHello', methods = ['DELETE'])
def deleteRequestHello():
    return "Deleting your hard drive.....haha just kidding! I received a DELETE request!"

if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=8000)

我安装了一个带有流浪汉的虚拟机,它运行完美。当我尝试在计算机上运行此代码(我在本地计算机上尝试并遇到相同的问题)时,终端返回以下内容:

vagrant@vagrant:/vagrant$ python api_server.py
 * Serving Flask app "api_server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 203-304-000

因此,我尝试访问http://0.0.0.0:8000/上的页面,但收到此错误“ ERR_ADDRESS_INVALID”。当我尝试使用http://127.0.0.1:8000(不确定有什么区别,但是我发现它对某些人有用)时,我收到另一个错误,这次找不到404页。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您未添加“ /”路由监听

@app.route('/')
def getMainRequest():
    return "Hi, Server is running fine!"