I'm writing a python script to automate some bash commands and am having trouble with passing a variable inside the curl command. This is what I have:
subprocess.call('''curl -H 'Content-Type: application/json' -X PUT -d '{"name": "{}".format(someVariable), "hive_ql": "CREATE VIEW user_balance AS SELECT NAME, LOB,ACCOUNT,BALANCE FROM csvtable"}' localhost:someport/api''', shell=True)
I'm trying to pass a variable in for the 'name' parameter, denoted by 'someVariable' in this example. But I get an error stating:
"message": "Failed to decode JSON object: Expecting ',' delimiter: line 1 column 14 (char 13):
When I replace the format part with an actual string, the script executes just fine so I know I'm doing something wrong with passing the variable between the quotes, just not sure what the correct syntax is.
calltakes a list of strings. See the docs: docs.python.org/3/library/subprocess.html#subprocess.runjson.dumps.