2021年4月5日星期一

Trying to access my Python flask webservice from Internet, I reach the server howver it return 404 if I use 127.0.0.1 it works but not actual IP

Issue: Trying to access my webservice from Internet, call reaches the service but service returns 404, even if I try my local IP adress same issue when I use 127.0.0.1:5000 it works

from flask import Flask, jsonify    app = Flask(__name__)  courses= [{'name':"Dirty Corporate Dairy",             'course_id': "0",             'Description': "Story about ",             'Price':"120"},            {'name': "Dirty Corporate Dairy 2",             'course_id': "1",             'Description': "Story about ",             'Price':"1200"},            {'name': "Dirty Corporate Dairy3",             'course_id': "2",             'Description': "Story about ",             'Price':"12000"}            ]      if __name__ == '__main__':      from waitress import serve      app.run(host='192.168.0.113',debug=True,port=80)    @app.route('/')  def index():      return "Welcome To the Course API"    @app.route("/courses", methods=['Get'])  def get():      return jsonify({'Courses': courses})    @app.route("/courses/<int:course_id>", methods=['Get'])  def get_course(course_id):      return jsonify({'Courses': courses[course_id]})    @app.route("/courses", methods=['Post'])  def create():      course={'name': "Dirty Corporate Dairy7",             'course_id': "6",             'Description': "Story about",             'Price':"120000000"}      courses.append(course)      return jsonify({'Created': course})    @app.route("/courses/<int:course_id>", methods=['Put'])  def update(course_id):      courses[course_id]["Description"] = "New Updated Description"      return jsonify({'Courses': courses[course_id]})    if __name__ == "__main__":      app.run(debug=True)  

Log:

  • Serving Flask app "main" (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

  • Restarting with stat

  • Debugger is active!

  • Debugger PIN: 186-690-898

  • Running on http://192.168.0.113:80/ (Press CTRL+C to quit)

    192.168.0.113 - - [05/Apr/2021 18:44:32] "←[33mGET / HTTP/1.1←[0m" 404 - 192.168.0.113 - - [05/Apr/2021 18:44:40] "←[33mGET / HTTP/1.1←[0m" 404 - 157.48.141.253 - - [05/Apr/2021 18:47:41] "←[33mGET /courses HTTP/1.1←[0m" 404 -

https://stackoverflow.com/questions/66953851/trying-to-access-my-python-flask-webservice-from-internet-i-reach-the-server-ho April 05, 2021 at 09:29PM

没有评论:

发表评论