Reputation: 140
I have an API endpoint as follows:
http://127.0.0.1:5000/data?params= spanish, italian, english
and this is my code in myflask.py:
@app.route("/data", methods=["GET"])
def my_api():
query = "SELECT * from tablex WHERE "
params = request.args.get("params")
if params:
query += "col IN ('{}');".format(params)
What I expect in output is this query:
"SELECT * from tablex WHERE col in ('spanish', 'italian', 'english');"
But what I get is
"SELECT * from tablex WHERE col in ('spanish, italian, english');"
I also tried this:
query += "col IN ('{}');".format(','.join(params))
but didn't work
Upvotes: 0
Views: 248
Reputation: 2094
Maybe this can help you :
languages = ['spanish','italian','english']
string = ','.join(['%s'] * len(languages))
print("SELECT * from tablex WHERE col IN (%s)" % string,tuple(languages))
But I would recommend that you change the SELECT for a PROCEDURE.
Upvotes: 1