I am trying to be able to remotely turn off my TV and the following curl call works like a charm:
curl -v -XPOST http://[your_TV's_IP_address]/sony/IRCC -d '<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:X_SendIRCC xmlns:u="urn:schemas-sony-com:service:IRCC:1"><IRCCCode>AAAAAQAAAAEAAAAVAw==</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>' -H 'Content-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"' -H 'X-Auth-PSK: [your_PSK]'
However, I can't port this into a python.requests.post
call as I always get an
Error 500
in return.
I must be doing something wrong in passing the XML data or the headers to requests.
Here is my python code:
import requests TurnOnOffcommandData = "<?xml version='1.0'?><s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/' s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><s:Body><u:X_SendIRCC xmlns:u='urn:schemas-sony-com:service:IRCC:1'><IRCCCode>AAAAAQAAAAEAAAAVAw==</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" TurnOnOffcommandHeaders = {'Content-Type': 'text/xml; charset=UTF-8', 'SOAPACTION': 'urn:schemas-sony-com:service:IRCC:1#X_SendIRCC', 'X-Auth-PSK': 'PASSWORD'} requests.post('http://XX.XX.XX.XX/sony/IRCC', headers=TurnOnOffcommandHeaders, data=TurnOnOffcommandData)
Thank you for any help on this issue.