python - Why do I keep having a "Not found" error when I call these methods? -
i using flask in python , trying elaborate post requests on server hosting (atm on localhost because still trying make work).
the post message generated in following way:
payload = {'k' : '123' } r = requests.post ('http://localhost', payload)
and result is
<!doctype html public "-//w3c//dtd html 3.2 final//en"> <title>405 method not allowed</title> <h1>method not allowed</h1> <p>the method not allowed requested url.</p>
at same time, if try send same request address localhost/post follows
r2 = requests.post ('http://localhost/post', data)
the result becomes
<!doctype html public "-//w3c//dtd html 3.2 final//en"> <title>404 not found</title> <h1>not found</h1> <p>the requested url not found on server. if entered url manually please check spelling , try again.</p>
the code using create server following:
from flask import flask, jsonify, request flask.templating import render_template flask.globals import request app = flask(__name__) @app.route('/', methods = ['get', 'post']) def index (): return render_template('indexserver.html') @app.route('/post', methods =['get', 'post']) def post(): return render_template('response.html') if __name__ == '__main__': app.run(host = 'localhost', port = 80, debug = true)
now, while method in index function works, doesn't when try '/post' page. guess reason behind same 404 above when try post.
i'd understand why happening, can't figure out going on , doing wrong. if wasn't obvious, have started working in python flask may anything.
thanks attention.
your code looks fine - looks me flask application isn't listening on port 80 expect to.
there many reasons - perhaps existing process using port 80
, therfore flask application cannot bind it. or in many oses, need run process root
bind port less 1024
. recommend change bind port 8088
:
if __name__ == '__main__': app.run(host = 'localhost', port = 8088, debug = true)
and try requests again:
r2 = requests.post ('http://localhost:8088/post', data)
Comments
Post a Comment