a11eksandar
a11eksandar

Reputation: 315

how to call curl in python with variables defined?

I have a python script which should execute curl command. I used os.system. command is:

os.system("curl -d 'protection=$protection&Code=$Code' -X POST https://xyz.somecompany.com/web/services/final.php")

and I get and error:

Code missingCode missingWorker with sessionID:xyz

I gues this is a problem with variable which is defined in python script but it can not be called in curl command? or im wrong?

variables are defined in python script as follows:

Code = item.decode("utf-8")
protection = (int(Code) - int(year)) / 2

Upvotes: 0

Views: 1038

Answers (1)

var211
var211

Reputation: 606

You can do it like this:

cmd = "curl -d 'protection={protection}&Code={code}' -X POST https://xyz.somecompany.com/web/services/final.php"
os.system(cmd.format(protection=protection, code=Code))

Upvotes: 1

Related Questions