Im seeking a little guidance, or help on the following. Apparently its a fairly simple issue, but Im struggling.
I'm trying to control my Viera Panasonic TV, and if I can get the basic code working, will look to construct what I hope is a simple plugin. I just cant get the python to work.
I have the following xml data that is posted with headers to the TV.
XML
<?xml version"1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlso.../soap/envelope/" s:encodingStyle="http://schemas.xmlso.../soap/encoding/">
<s:Body>
<u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1">
<X_KeyEvent>NRC_MUTE-ONOFF</X_KeyEvent>
</u:X_SendKey>
</s:Body>
</s:Envelope>
Header
Accept: text/xml
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/xml;charset="utf-8"
SOAPACTION: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey\"
Content-Length:324
Posted 'to' (http://192.168.1.55:55000/nrc/control_0)
Now, I can get this to work from Cromes Postman app all well and good, and can send any of the commands needed to control the TV.
The Postman app generates the python code below, which requires the 'requests' module, which I have confirmed is installed for python 2.6. However, when I run the code below on the same machine as Postman (or any other computer), I get a 400 error from the TV. I've tried a script within indigo and from PyCharm.
I've been looking at this for a week or so, and would be grateful for some guidance please. Thanks.
- Code: Select all
import requests
url = "http://192.168.1.55:55000/nrc/control_0"
payload = "<?xml version\"1.0\" encoding=\"utf-8\"?>\n<s:Envelope xmlns:s=\"http://schemas.xmlso.../soap/envelope/\" s:encodingStyle=\"http://schemas.xmlso.../soap/encoding/\">\n<s:Body>\n<u:X_SendKey xmlns:u=\"urn:panasonic-com:service:p00NetworkControl:1\">\n<X_KeyEvent>NRC_MUTE-ONOFF</X_KeyEvent>\n</u:X_SendKey>\n</s:Body>\n</s:Envelope>"
headers = {
'accept': "text/xml",
'cache-control': "no-cache",
'pragma': "no-cache",
'content-type': "text/xml;charset=\"utf-8\"",
'soapaction': "\"urnpanasonic-comservicep00NetworkControl1#X_SendKey\\"",
'content-length': "324",
'postman-token': "e17a5e11-b628-faa7-cac3-7391c01d8c0f"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)