简体   繁体   English

为什么我得到 404 Not Found in Flask

[英]Why Do I get 404 Not Found in Flask

For Flask every time I try to start the server I get 404 Not found and it says:对于 Flask,每次我尝试启动服务器时,我都会收到404 Not found并显示:

Not Found The requested URL was not found on the server. Not Found 在服务器上找不到请求的 URL。 If you entered the URL manually please check your spelling and try again.如果您手动输入 URL,请检查您的拼写并重试。

My code:我的代码:

import requests
from API import CHAT_ID, TOKEN
from flask import Flask, request
    
    
    
    
app = Flask(__name__)



@app.route('/call-status', methods=['POST'])
def call_status():
     call_status = request.form['CallStatus']
    
       requests.post(f"https://api.telegram.org/bot{TOKEN}/sendMessage",
                        params={"chat_id": CHAT_ID, "text": call_status})
      return "OK"

    if __name__ == '__main__':
        app.run(host='127.0.0.1', port=5000)

I've tried to use different ports, rather than trying the same port 5000 I have even tried to run an even simpler ***Flask ***script:我尝试使用不同的端口,而不是尝试使用相同的端口 5000 我什至尝试运行一个更简单的 ***Flask ***脚本:

from flask import Flask

@app.route('/')
def index():
    return 'Hello world!'

if __name__ == "__name__":
    app.run(host="127.0.0.7", port='5000')

PS I'm new to coding and all of this, if you could dumb some of the more complicated suggestions down a little that would be greatly appreciated PS 我是编码和所有这些的新手,如果你能把一些更复杂的建议简化一点,我将不胜感激

Response from Flask:来自 Flask 的回复:

* Running on http://127.0.0.1:5000
Press CTRL+C to quit
127.0.0.1 - - [11/Jan/2023 22:43:56] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [11/Jan/2023 22:43:56] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [11/Jan/2023 22:43:58] "GET / HTTP/1.1" 404 -

tl;dr: Works great! tl;博士:效果很好!

I am running this code, on a macos 12.6.2 laptop, with cPython 3.10.8 and flask 2.2.2.我在 macos 12.6.2 笔记本电脑上运行这段代码,使用 cPython 3.10.8 和 flask 2.2.2。

import requests
from flask import Flask, request

app = Flask(__name__)


@app.route("/")
def index():
    return "Hello world!"


if __name__ == "__main__":
    app.run(host="127.0.0.1", port="5000")

In a chrome browser it greets me just fine, and logs a 200 GET.在 chrome 浏览器中,它很好地迎接我,并记录了200 GET。

Either you aren't running exactly that code, or some aspect of your hosting setup is broken in ways the question does not yet describe.要么您没有完全运行该代码,要么您的托管设置的某些方面以问题尚未描述的方式被破坏。

(The logged console output was very helpful BTW, thank you.) (记录的控制台 output 对顺便说一句很有帮助,谢谢。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM