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'
  • 1
    See https://stackoverflow.com/questions/89228/calling-an-external-command-in-python/92395#92395 – diciu Mar 12 '19 at 04:19
  • For HTTP you can use the [requests](http://docs.python-requests.org/en/master/) library. It's very versatile. – Klaus D. Mar 12 '19 at 04:28

2 Answers2

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)
Netwave
  • 40,134
  • 6
  • 50
  • 93
JacobIRR
  • 8,545
  • 8
  • 39
  • 68
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.

Nitin Labhishetty
  • 1,290
  • 2
  • 21
  • 41