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

1 answer

  • answered 2022-05-04 10:40 var211

    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))
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum