0

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.

  • 1
    Your python code, please? It would be needed to help pinpoint what you're doing wrong. – A. Rose Feb 02 '19 at 23:10
  • @A.Rose thank you for your answer! I added my code in my initial question above. – Laurent de Barry Feb 06 '19 at 11:34
  • I don't have a TV that does this, so I can't help debug - and there's nothing obviously wrong with your code. HTTP 500 is an internal server error. You can also try this se question for more info: https://stackoverflow.com/questions/18175489/sending-soap-request-using-python-requests – A. Rose Feb 15 '19 at 04:23

1 Answers1

0

Assume you've solved this by now but it looks like you've missed the quotes in the SOAPACTION header.

It should be: 'SOAPACTION': '"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"'