bash - Adding variable inside quotes in a python script -


i'm writing python script automate bash commands , having trouble passing variable inside curl command. have:

subprocess.call('''curl -h 'content-type: application/json' -x put -d '{"name": "{}".format(somevariable), "hive_ql": "create view user_balance select name, lob,account,balance csvtable"}' localhost:someport/api''', shell=true)

i'm trying pass variable in 'name' parameter, denoted 'somevariable' in example. error stating:

"message": "failed decode json object: expecting ',' delimiter: line 1 column 14 (char 13):

when replace format part actual string, script executes fine know i'm doing wrong passing variable between quotes, not sure correct syntax is.

it clearer pass list subprocess.call:

import json import subprocess  somevariable = 'hello' hive_ql = 'create view user_balance select name, lob,account,balance csvtable'  # noqa  subprocess.call([     'curl',     '-h',     'content-type: application/json',     '-x',     'put',     '-d',     json.dumps({       'name': str(somevariable),       'hive_ql': hive_ql     }),     'localhost:someport/api' ]) 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -