1

I want to send this command in a python program. How can I do this? I do not need to print any response.

curl -k -X PUT 'http://10.210.12.158:10065/iot/put_bulb/true?id=4'
2

2 Answers 2

1

Using os:

from os import system
system("curl -k -X PUT 'http://10.210.12.158:10065/iot/put_bulb/true?id=4'")

Using subprocess:

subprocess.Popen("curl -k -X PUT 'http://10.210.12.158:10065/iot/put_bulb/true?id=4'", shell=True)
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the shell module to run such commands neatly:

>>> from shell import shell
>>> curl = shell("curl -k -X PUT 'http://10.210.12.158:10065/iot/put_bulb/true?id=4'")
>>> curl.output()

Alternatively, I'd suggest using the requests module for making such http requests from Python.

1 Comment

Python has 3 different modules that allow comnand execution built-in. Why an other external one?

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.