Answer a question

This is similar to the question and example asked here: Flask request.args.get get all params (Python).

Not sure if I'm using request.args.get() incorrectly, but I am only able to get the first parameter passed through. For example, for my flask app:

@app.route('/longword/')
def longword():

    gid = request.args.get('gameid')
    pid = request.args.get('playerid')
    print("param1: ", gid, "\n")
    print("param2: ", pid, "\n")
    print("request args", request.args)

    return "GID: %s  PID: %s" % (gid, pid)

app.run()

and my query: curl http://localhost:5000/longword/?gameid=123&playerid=456, I am always getting the first parameter but the second parameter always returns none.

param1:  123 

param2:  None 

request args ImmutableMultiDict([('gameid', '123')])

Answers

Put your url in double quotes like this when using curl

curl "http://localhost:5000/longword/?gameid=123&playerid=456"

credit to Bidhan here

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐