1

Using this:

query_string = "This is some string"
subprocess.call('curl -X POST -d "{\\"query\\":\\"${query_string}\\"}" 0.0.0.0:5000/query --header "Content-Type:application/json"', shell=True)

and having this endpoint in my Flask app:

@app.route('/query', methods=['GET', 'POST'])

def new_user():
   user_data = request.get_json()  
   print(user_data)

return jsonify(user_data)

when I run the curl command as defined above, the response I get from Flask server is:

"POST /query HTTP/1.1" 200 - {'query': ''}

How can I pass the actual content of the parameter : query_string to the Flask endpoint?

Ali AzG
  • 1,861
  • 2
  • 18
  • 28

1 Answers1

1

you need to pass it like so:

subprocess.call('curl -X POST -d "query=%s" 0.0.0.0:5000/query --header "Content-Type:application/json"'% query_string, shell=True)
LinPy
  • 16,987
  • 4
  • 43
  • 57