简体   繁体   中英

Route doesn't exist

I have the following code on my service and when requested the return is always 404.

@app.route('/v1/auth/service', methods=['POST'])
def verifyAuthService():
    data = request.get_json()

But in the log file, the service returns 404.

127.0.0.1 - - [TIMEVALUE] "POST /v1/auth/service HTTP/1.1" 404 -

But it works when I use other route. I have checked if the route path or method name are duplicated and didn't find anything.

I request the service method with the following code:

r = requests.post("http://myservice.com:5001/v1/auth/service", json=jPayload)

Maybe was a newbie error, in my init.py file, I haven't imported auth_services.py .

The /v1/auth/service route wasn't interpreted by python so, the route was inaccessible.

Can you try building the URL with below code and match if the route is pointing to exactly same URL which you have called.

from flask import Flask, url_for

app = Flask(__name__)

@app.route('/v1/auth/service', methods=['POST'])
def verifyAuthService():
    data = request.get_json()

with app.test_request_context():
    print url_for('verifyAuthService')

Hope this helps!

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