buymyopps2021-01-15 19:15:33
buymyopps, 2021-01-15 19:15:33

404 error while processing flask get request?

Hello. There is a 404 error when trying to make a get request to the server on flask.

The request looks like this:

And here is the server code:

from flask import Flask

app = Flask(__name__)

@app.route("/?MERCHANT_ID=<shop_id>&AMOUNT=<price>&intid=<op_id>&MERCHANT_ORDER_ID=<chat_id>", methods=['GET'])
def hello(shop_id,price,op_id,chat_id):
    return f"{chat_id}"

app.run(host = "", port = 80)

The program runs on a remote computer. The port is open. If you just return "hello world" everything works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Ivan Yakushenko, 2021-01-15

In route rules, you can only set address parameters, that is, if you write

@app.route(rule='/<foo>/<bar>', methods=['GET'])
def index(foo, bar):

This will mean that fooand barare address parameters, that is, example.com/asda/dasda. If you need to get address arguments, for example example.com/?foo=asda, then you need to use request.args, that is:
from flask import request

@app.route(rule='/', methods=['GET'])
def index():
    if request.args.get('foo'):
        return f'{request.args["foo"]}'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question