I'm having some problems with the following command:
> curl -d "{\"id\": 20, \"status\": 0}" -H "Content-Type: application/json" -X POST http://192.168.5.204:8080/Relay"
I'm trying to connect to a raspberry.
If I type this command directly on a CMD that I open personally, the command works fine:
When, instead, via Python I send this command
os.system('cmd /k "curl -d "{\"id\": 20, \"status\": 0}" -H "Content-Type: application/json" -X POST http://192.168.5.204:8080/Relay"')
seems that the command is not performed. I've added the /k in order to see what is going on on the shell and this is the error I have:
I'm not an expert but to me seems that in somehow it is not "building" the address in the correct way, or is something else?
1 Answer 1
I've found the solution to my problem by using the next code in Python.
url="192.168.5.204:8080/Relay"
payload = {'id': 20,'status': 1}
headers = {'Content-Type':'application/json'}
requests.post(url, json=payload, headers=headers, allow_redirects=True)
eduardosufan
1,5932 gold badges26 silver badges55 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
/Relay"- what if you remove that last quote character?cmd /k "curl -d "{\"id\": 20, \"status\": 0}" -H "Content-Type: application/json" -X POST http://192.168.5.204:8080/Relay"the actual received resultant command would be printed as the first line of the open cmd.exe window. Is there any particular reason therefore why you have not posted that line, or at the very least compared it with,C:\python>curl -d "{\"id\": 20, \"status\": 0}" -H "Content-Type: application/json" -X POST http://192.168.5.204:8080/Relayto see if all of the characters have been passed to and received correctly by cmd.exe?