0

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
4
  • 1
    Why use curl instead of one of pythons request libraries? Commented May 4, 2022 at 10:31
  • I`m not so good with python. What would be correct syntax to rewrite this command with python request libraries Commented May 4, 2022 at 10:33
  • Does this answer your question? How do I put a variable’s value inside a string? Commented May 4, 2022 at 10:35
  • Or use subprocess, or requests, ... Commented May 4, 2022 at 10:36

1 Answer 1

1

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.