Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

http post to loxone miniserver

If you have a question or need help, this is the place to be.
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

http post to loxone miniserver

Post by skribb »

IFTTT can now receive web requests and I'd like to use that functionality!

Is there a plugin for that or do I need to script something in Python?

Much appreciated :D
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

http post to loxone miniserver

Post by kgschlosser »

python script, place the URL where is states SOME.URL.HERE

Code: Select all

URL = http:\\"SOME.URL.HERE" (leave the double quotes alone)


import urllib2 as urllib

try:
    response = urllib.urlopen(URL)
    print response
except urllib2.HTTPError as err:
    print err

If you like the work I have been doing then feel free to Image
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

http post to loxone miniserver

Post by skribb »

Thanks, :D :D

is "try" an arbitrary name you chose or is that the function for sending a POST? ( I am at a novice level of programming and I haven't programmed properly since I studied it 10 years ago so my terminology is prolly not correct)
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

http post to loxone miniserver

Post by kgschlosser »

try:
except:

that is a way of catching traceback errors. so you don't get the ugly reg in the log if it can't connect, it will just print the actual webpage error instead

easier to ask for forgiveness then to ask permission

it's a saying for using the try and except

i don't remember what the actual term is for it tho.

let me know if that helps ya out

K
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

http post to loxone miniserver

Post by V_J »

I was trying to use the webserverplugin to send something to a different webserver, but failed. Now, I tried this one and it gives me a syntax error...

Code: Select all

URL = http:\\"user:passwd@ip:port\dev\sps\io\SetVariable\test"

import urllib2 as urllib

try:
    response = urllib.urlopen(URL)
    print response
except urllib2.HTTPError as err:
    print err
Syntax error is in the first line... I have a username without password for that server, but it also gives syntax error. If I do not put a username, it should not work due to lack of authentication, but I still get syntax error on the first line.... Any thoughts?
skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

http post to loxone miniserver

Post by skribb »

V_J wrote:I was trying to use the webserverplugin to send something to a different webserver, but failed. Now, I tried this one and it gives me a syntax error...

Code: Select all

URL = http:\\"user:passwd@ip:port\dev\sps\io\SetVariable\test"

import urllib2 as urllib

try:
    response = urllib.urlopen(URL)
    print response
except urllib2.HTTPError as err:
    print err
Syntax error is in the first line... I have a username without password for that server, but it also gives syntax error. If I do not put a username, it should not work due to lack of authentication, but I still get syntax error on the first line.... Any thoughts?
The URL should be formatted normally, i.e like this:

Code: Select all

URL = "http://user:passwd@ip:port/dev/sps/io/SetVariable/test"
KG made a typo in their code snippet. I also got syntax error before I changed the URL formatting
Automation is life.

Win7 64bit
EG: v0.5.0-rc4
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

http post to loxone miniserver

Post by kgschlosser »

hey i didn't know there was username and passwords involved.

in my defense

that's why the error handling, it's supposed to print out the exact reason why it can't connect

and i guess it worked because you figured out the username and password bits
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

http post to loxone miniserver

Post by kgschlosser »

it was just a generalized way of opening a webpage, that can be used for connecting to pretty much any webpage.

just like you would enter a :81 after the server if the webserver was hosting the page on port 81
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

http post to loxone miniserver

Post by kgschlosser »

DOAH!!!! the double quotes

oopsies

LMAO

just noticed that

***BANGS HEAD AGAINST WALL***
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

http post to loxone miniserver

Post by V_J »

Not sure why I had so much issues with the url... But I still get an error:
-
Traceback (most recent call last):
Python script "5", line 8, in <module>
except urllib2.HTTPError as err:
NameError: name 'urllib2' is not defined
-

Any thoughts?
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

http post to loxone miniserver

Post by kgschlosser »

my god i have really messed this thing up i must have been tired

Code: Select all

URL = "http:\\user:passwd@ip:port\dev\sps\io\SetVariable\test"

import urllib2

try:
    response = urllib2.urlopen(URL)
    print response
except urllib2.HTTPError as err:
    print err

maybe this will work now
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

http post to loxone miniserver

Post by V_J »

It gives an error still, but I'm quite sure the error is not in the code snippet...
-
Traceback (most recent call last):
Python script "5", line 6, in <module>
response = urllib2.urlopen(URL)
File "urllib2.pyc", line 126, in urlopen
File "urllib2.pyc", line 391, in open
File "urllib2.pyc", line 409, in _open
File "urllib2.pyc", line 369, in _call_chain
File "urllib2.pyc", line 1161, in http_open
File "urllib2.pyc", line 1136, in do_open
URLError: <urlopen error [Errno 11003] getaddrinfo failed>
-

FWIW, if I send to this webserver using the webserver plugin, I get
-
Webserver: Send event to another webserver:
The authentication line is badly formed.
-
Not sure if both errors are related though...
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

http post to loxone miniserver

Post by kgschlosser »

here is a working version i checked it.

Code: Select all

URL = "http://www.google.com"

import urllib2

try:
    print urllib2.urlopen(URL).read()
except urllib2.HTTPError as err:
    print 'urllib2 Webpage Error: ', str(err)

i really must have had a bad week. forgot to read the response and also had the //'s backwards in the url
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

ok, so it looks exactly the same, but fails... Do I have to encode the @ maybe?
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

Googled a bit, and learned that there is an issue with the syntax "http://username:password@website/..."
http://stackoverflow.com/questions/4706 ... -in-python

So that may be why it fails both in the script and in the webserver...?
Post Reply