简体   繁体   中英

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:

Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

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:

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

Response from 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!

I am running this code, on a macos 12.6.2 laptop, with cPython 3.10.8 and 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.

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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