Page 1 of 1

[Answer] ZWaveAPI authentication via python

Posted: 04 Feb 2016 16:31
by holzemile
Hey, I just wanted to share this, because it took my some time to figure it out:

If you want to access the ZWaveAPI via python, but need authentification, you can use something like this:
(I'm using the requests module)

Code: Select all

r = requests.get("http://192.168.178.123/ZWaveAPI/Data/", auth=("admin", "PASSWORD"))
status_code = r.status_code   # should be 200
content = r.content
parsed = r.json()
The r.json() is very neat, but for performance purposes you should use something like ijson, which iteratively parses the json.


BTW: If the user/password is wrong, I don't get something like 'Failed to login' but:
401 - Not logged in
I hope I will save some time for someone ;)

Re: [Answer] ZWaveAPI authentication via python

Posted: 10 May 2016 18:56
by Mike Yeager
I am trying to use the line:

urllib2.urlopen('http://127.0.0.1:8083/ZWaveAPI/Data/'+ str(timeStamp))
device = OpenSite('http://127.0.0.1:8083/ZWaveAPI/Data/' + str(timeStamp))
data = json.loads(device.read())

from a python program to read the JSON data. It used to work just fine but not any longer.

http://127.0.0.1:8083/ZWaveAPI/Data/0 from a browser window on the RPi gets me 'permission denied. or .not logged in'. I can use this from another computer (once I've logged into the ZWay GUI page) to get the JSON stream. I'm going to dig into this requests library to see if I can figure out how to make it work for me but if you could lend a hand, I'd appreciate it...

Actually, it was considerably easier than I thought. Thank you for pointing this out. Hopefully it won't be broken by the next release....

Now to make the rest of it work again.....