REST api call works but prints access denied in the log.

Posted on
Mon Jan 24, 2022 5:55 pm
anitchalk offline
Posts: 21
Joined: Nov 29, 2019

REST api call works but prints access denied in the log.

Hi, apologies if this question has been answered a million times already, but I'm making a rest call (using the requests lib in python). I'm using digest auth and hitting my indigo instance via my LAN over http. the first var I hit is keylock. I step over it and it changes just fine. The next var I hit is sendWarningNotification which has an associated trigger on it that will send me a pushover notification. Here's the log

Code: Select all
   Web Server                      request to set variable "foo" value to "test" from 192.168.10.4
   Web Server                      request to set variable "sendWarningNotification" value to "warning test" from 192.1.1.1
   Trigger                         SendWarningNotification
   Web Server                      access denied "http://foo.lan:8176/variables/sendWarningNotification.json" from bar @ 192.1.1.1
   Pushover                        Pushover notification was sent sucessfully, title: Warning Error, body: warning test


What's weird is that the call to change sendWarningNotification works just fine, the trigger fires, I get my pushover notification, but there is still the "access denied" msg in the log. So, long story short it all works! but obviously it's odd that there's any error here. Should I care? or is there some config I messed up somewhere?

Posted on
Tue Jan 25, 2022 11:22 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST api call works but prints access denied in the log.

What exactly does the trigger do? I ask because it's odd that there's an attempted access after the trigger fires. Updating a variable would cause no such request.

Also, if you disable the trigger, do you still see the error?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 25, 2022 2:46 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: REST api call works but prints access denied in the log.

Did you edit those IP addresses? They don't match, and one looks to be your router. Please show the Python script that's sending the requests.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Feb 02, 2022 11:06 pm
anitchalk offline
Posts: 21
Joined: Nov 29, 2019

Re: REST api call works but prints access denied in the log.

apologies, first time posting and I assumed I'd get an email notification on a response, but looks like I had that setting toggled off in my profile!
I did a poor job of sanitizing some of the ips/msgs/user etc. I think I did a better job below. All the requests are coming from the same machine (192.168.20.10) TO foo.lan. Again, the variables ARE updating and the trigger IS firing

Code: Select all
Web Server                      request to set variable "foo" value to "bar" from 192.168.20.10
Web Server                      access denied "http://foo.lan:8176/variables/foo.json" from myuser @ 192.168.20.10
Web Server                      request to set variable "sendCriticalNotification" value to "bar" from 192.168.20.10
Trigger                         SendCritNotification
Web Server                      access denied "http://foo.lan:8176/variables/sendCriticalNotification.json" from myuser @ 192.168.20.10
Pushover                        Pushover notification was sent sucessfully, title: Critical Error, body: bar


I've attached a screen shot of the trigger. All it does is send a pushover notification upon a change of that var. Makes it an easy way for me to send notifications from the various services I have running in my house via a simple http request.

As for the python code, it's pretty straight forward (I think?)
Code: Select all
digest_auth = HTTPDigestAuth(os.environ["INDIGO_USER"], os.environ["INDIGO_PWD"])
def set_indigo_var(var, value):
    data = {"value": value}
    reply = requests.put(
        f"http://foo.lan:8176/variables/{var}.json", auth=digest_auth, data=data
    )


As you can see in the log msgs above, only one of the vars that I change has a trigger, but the access denied msg happens when I try to set either variable (and they both update just fine).
Attachments
Screen Shot 2022-02-02 at 10.56.37 PM.png
Here's what the trigger does.
Screen Shot 2022-02-02 at 10.56.37 PM.png (44.82 KiB) Viewed 2188 times

Posted on
Thu Feb 03, 2022 10:40 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST api call works but prints access denied in the log.

How exactly are you running the python script? I can't seem to reproduce your behavior. Using this script:

Code: Select all
import requests
from requests.auth import HTTPDigestAuth
import os

digest_auth = HTTPDigestAuth(os.environ["INDIGO_USER"], os.environ["INDIGO_PWD"])
def set_indigo_var(var, value):
    data = {"value": value}
    reply = requests.put(
        f"http://localhost:8176/variables/{var}.json", auth=digest_auth, data=data
    )

set_indigo_var("foo", "bar")


When I run it from the command line:

Code: Select all
python3 var_set.py


I get this in the Event Log window:

Code: Select all
Feb 3, 2022 at 10:38:31 AM
   Web Server                      request to set variable "foo" value to "bar" from 127.0.0.1


That's it, nothing else. So in order for me to further try to reproduce, I need to know the specifics of how you are executing the script, from where, what specific version of Python and the requests lib, etc.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 03, 2022 9:47 pm
anitchalk offline
Posts: 21
Joined: Nov 29, 2019

Re: REST api call works but prints access denied in the log.

I appreciate you kicking the tires for me. Well I can't post the entire script that I'm running, but I did do what you did and ripped out the bare minimum from my larger script and somehow (of course) that works JUST fine! So I guess this is on me to figure out why when I call it in one place there's an error and in another place there isn't! Anyway, I thought maybe when I posted that error there was something obvious that might pop out from the experts here, but clearly this is of my own doing! If I figure it out I'll post back here.

Thanks again.

Posted on
Thu Feb 03, 2022 11:03 pm
anitchalk offline
Posts: 21
Joined: Nov 29, 2019

Re: REST api call works but prints access denied in the log.

Well, one more data point. I was able to whittle it down a bit more. I realized that at the beginning of my script I do a get call using this function:

Code: Select all
def get_indigo_var(var):
    reply = requests.get(
        f"http://foo.lan:8176/variables/{var}.json", auth=digest_auth
    )
    return reply.json()


Note this is using the same digest_auth object I create at the top of my script. Anyway, seems like if I make this call and then do the put, it gives me that access denied msg. However if I simply remove this get call first and just do the put.... lo and behold no access denied msg. I'm not very familiar with the requests lib. Seems like there are no issues using curl so maybe I'll just bite the bullet and subprocess the call and forget about this. Or if I get a little more time I can see if anything else comes to mind (maybe tcpdump or something). Anyway, just wanted to update in case something popped to mind.

Posted on
Fri Feb 04, 2022 8:37 am
anitchalk offline
Posts: 21
Joined: Nov 29, 2019

Re: REST api call works but prints access denied in the log.

oh, and you had asked what versions I was using.


> python --version returns:
Python 3.9.4


> pip freeze | grep req
requests==2.25.1
requests-oauthlib==1.3.0

Posted on
Fri Feb 04, 2022 3:51 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST api call works but prints access denied in the log.

anitchalk wrote:
Note this is using the same digest_auth object I create at the top of my script.


And you're positive that the digest_auth object is valid at the time it's called? Sure sounds like it's not, so no authentication data is getting passed, thus the 401...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 13, 2022 2:17 pm
anitchalk offline
Posts: 21
Joined: Nov 29, 2019

Re: REST api call works but prints access denied in the log.

Sorry I left this open ended. I have another question to ask, so I thought maybe instead of being an ingrate, I'd close this off :)

Anyway, I think I know what's going on here, and ugh for the life of me I can't find where I read the actual reason. But here's someone else with the same issue:
https://stackoverflow.com/questions/701 ... al-request
Seems that the python requests lib always sends an unathenticated req first and then an authenticated one. Anyway, at this point I didn't care since I barely make these calls, and it only happens on the first attempt.

Posted on
Wed Apr 13, 2022 4:35 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST api call works but prints access denied in the log.

That's how HTTP Digest Auth works - the client sends a request to the server, server replies that it needs authentication, client sends the authentication data.

I don't believe that was the problem in the OP... :)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest