Chathura Jayawardane
Chathura Jayawardane

Reputation: 47

how to use CURL commands in PYTHON

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'

Upvotes: 1

Views: 107

Answers (2)

JacobIRR
JacobIRR

Reputation: 8946

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)

Upvotes: 1

Nitin Labhishetty
Nitin Labhishetty

Reputation: 1347

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.

Upvotes: 1

Related Questions