3

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')])
bwang
  • 49
  • 7
  • The code looks correct to me... For some reason it's not picking up on your second querystring parameter. – Rexovas Jun 04 '20 at 23:15

1 Answers1

6

Put your url in double quotes like this when using curl

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

credit to Bidhan here

Rexovas
  • 469
  • 2
  • 9