Need Help from Python Guru...
#1
the goal is to be able to send http post to a homeseer web server (home automation software which is very popular).

according to the homeseer documentation a simple http command should be accepted directly. if i'm reading it correctly?

here's the page in the online manual for homeseer with the info: homeseer info on controlling devices from html

i simplified my .py to only 2 lines...
Quote:import urllib
urllib.urlopen('http://192.168.1.11', urllib.urlencode({'control_device': 'kitchen lights=off'}))

error on xbmc log...
Quote:file "q:\python\python23.zlib\urllib.py", line 78, in urlopen
file "q:\python\python23.zlib\urllib.py", line 183, in open
file "q:\python\python23.zlib\urllib.py", line 297, in open_http
file "q:\python\python23.zlib\httplib.py", line 712, in endheaders
file "q:\python\python23.zlib\httplib.py", line 597, in _send_output
file "q:\python\python23.zlib\httplib.py", line 564, in send
file "q:\python\python23.zlib\httplib.py", line 548, in connect
ioerror
:
[errno socket error] (10060, 'operation timed out')

i've taken the commands i'm using from working http & asp pages.

here's actual code from an html page i'm using for the same device i'm trying in my .py...
Quote:<form method="post">
<td nowrap class="tableroweven">
<a name="bm83274"></a>
<input type="hidden" name="bookmark" value="83274">
<input type="hidden" name="ref_page" value="stat">
<input type="hidden" name="control_device" value="kitchen lights">
<input class="formbutton" type="submit" name="action_on" value="on">
<input class="formbutton" type="submit" name="action_off" value="off">
<select class="formdropdown" name="selectdim" size="1"
onchange="submitform(this)">
<option selected value="0">0%</option>
<option value="10">10%</option>
<option value="20">20%</option>
<option value="30">30%</option>
<option value="40">40%</option>
<option value="50">50%</option>
<option value="60">60%</option>
<option value="70">70%</option>
<option value="80">80%</option>
<option value="90">90%</option>
<option value="100">100%</option>
</select>
</td></form>



I'm not an expert but I play one at work.
Reply
#2
the post statement looks fine but it seems like it can't connect. i think you need to specify the specific asp page in that url (the page that the submit goes to.

try looking at that submitform() javascript function that gets called to see if your url is ok.
Reply
#3
asteron,
i found the script code:

Quote:<script>
function submitform(button) {
document.dimform.selectdim.value = button.form.elements["selectdim"].value
document.dimform.control_device.value = button.form.elements["control_device"].value
document.dimform.bookmark.value = button.form.elements["bookmark"].value
document.dimform.submit();
}
function submitformvalue(button) {
document.dimformvalue.selectvalue.value = button.form.elements["selectvalue"].value
document.dimformvalue.control_device.value = button.form.elements["control_device"].value
document.dimformvalue.bookmark.value = button.form.elements["bookmark"].value
document.dimformvalue.submit();
}
</script>

here's what i caputred from my browser...

bookmark=83274&ref_page=stat&control_device=kitchen+lights&action_on=on&selectdim=0

... i believe the only items necessary are starting with control_device.


i have some custom asp pages that i built and the stream looks like this...
action=image&commandimage=hs.execx10byname+%22kitchen+lights%22%2c+%22off%22%2c+100&x=4&y=6

... i'm not sure that anything is needed except the built-in homeseer function hs.execx10byname plus the params after it.


i get the same error no matter which of these commands i try:
Quote:urllib.urlopen('http://192.168.1.11/hact/kitchen.asp', urllib.urlencode({'action': 'hs.execx10byname+kitchen+lights%2c+on %2c+100&x=4&y=6'}))

Quote:urllib.urlopen('http://192.168.1.11/hact/kitchen.asp', urllib.urlencode({'commandimage': 'hs.execx10byname+kitchen+lights%2c+on %2c+100&x=4&y=6'}))

Quote:urllib.urlopen('http://192.168.1.11', 'control_device=kitchen+lights&action_on=on&selectdim=0')

Quote:urllib.urlopen('http://192.168.1.11', urllib.urlencode({'control_device': 'kitchen+lights&action_on=on&selectdim=0'}))


log:
Quote:info urllib.urlopen('http://192.168.1.11/hact/kitchen.asp',
urllib.urlencode({'action': 'hs.execx10byname+kitchen+lights%2c+on
%2c+100&x=4&y=6'}))
info
info   file "q:\python\python23.zlib\urllib.py", line 78, in urlopen
info   file "q:\python\python23.zlib\urllib.py", line 159, in open
info   file "q:\python\python23.zlib\urllib.py", line 957, in splittype
info attributeerror
info :
info 'module' object has no attribute 'compile'



if i use this code i get 'operation timed out'...


Quote:import urllib
data = urllib.urlencode({'control_device': 'kitchen+lights', 'action_on': 'on', 'selectdim': '0'})
urllib.urlopen('http://192.168.1.11', data)

log:
Quote:file "q:\python\python23.zlib\urllib.py", line 78, in urlopen
06-01-2006 15:09:51 info   file "q:\python\python23.zlib\urllib.py", line 183, in open
06-01-2006 15:09:51 info   file "q:\python\python23.zlib\urllib.py", line 297, in open_http
06-01-2006 15:09:51 info   file "q:\python\python23.zlib\httplib.py", line 712, in endheaders
06-01-2006 15:09:51 info   file "q:\python\python23.zlib\httplib.py", line 597, in _send_output
06-01-2006 15:09:51 info   file "q:\python\python23.zlib\httplib.py", line 564, in send
06-01-2006 15:09:51 info   file "q:\python\python23.zlib\httplib.py", line 548, in connect
06-01-2006 15:09:51 info ioerror
06-01-2006 15:09:51 info :
06-01-2006 15:09:51 info [errno socket error] (10060, 'operation timed out')



any thoughts?



I'm not an expert but I play one at work.
Reply
#4
those two asp lines look to be of different formats...
the first one in python i think would be

{'bookmark' : '83274', 'ref_page' : 'stat', 'control_device' : 'kitchen lights', 'action_on' : 'on', 'selectdim' : '0'}

and the second mapping looks like

{'action':'image','commandimage':'hs.execx10byname "kitchen lights", "off", 100','x':'4','y':'6'}

i think the urlencode thing will turn it into & delimted %escapes and turn space into +.
this is if i am reading the post right which i dont know but you should try these above.
Reply
#5
i update my previous post to be more "complete" with my current testing.

i tried your new suggested params line. i get the same error: [errno socket error] (10060, 'operation timed out')



I'm not an expert but I play one at work.
Reply

Logout Mark Read Team Forum Stats Members Help
Need Help from Python Guru...0