0

Here is my simple code:

from Flask import request

@app.route("/pods", methods=["GET"])
def list_pods():
    cluster = request.args.get("cluster")
    project = requests.args.get("project_name")
    
    print(cluster)
    print(project)

Running the following two cURL commands results in the second-defined variable to not get parsed:

$ curl localhost:51918/pods?cluster=nw-dc-blah&project_name=my_project
nw-dc-blah
None
$ curl localhost:51918/pods?project_name=my_project&cluster=nw-dc-blah
None
my_project

How can I get Flask to parse both GET arguments?

2 Answers2

1

As stated in Flask app - query parameters dropping out of request args

The cURL URL will need to have quotes around it to escape the & sign, as my Unix shell doesn't parse anything after that and send it to Flask.

$ curl "localhost:51918/pods?cluster=nw-dc-blah&project_name=my_project
nw-dc-blah"
1

To reproduce your example:

hello.py
 from flask import Flask,request
 
 app = Flask(__name__)
 
 @app.route("/pods", methods=["GET"])
 def list_pods():
     cluster = request.args.get("cluster")
     project = request.args.get("project_name")
 
     print(cluster)
     print(project)
     return "hello"

Then
flask --app hello run

Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes

USE (") else following:

➜  stackoverflow curl localhost:5000/pods?cluster=nw-dc-blah&project_name=my_project
[1] 96485
zsh: no matches found: localhost:5000/pods?cluster=nw-dc-blah
[1]  + 96485 exit 1     curl localhost:5000/pods?cluster=nw-dc-blah                                                 
➜  stackoverflow curl "localhost:5000/pods?cluster=nw-dc-blah&project_name=my_project"
hello%                                                                                                              
jacorl
  • 396
  • 2
  • 9