Reputation: 21
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?
Upvotes: 1
Views: 1093
Reputation: 18588
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)
Upvotes: 1