Sending URLs with authentication

Posted on
Thu Oct 31, 2019 10:18 am
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Sending URLs with authentication

I am stumped!

I'm trying to control a PTZ camera via its built-in web server, which requires authentication. I have the URLs working in Safari (and Chrome), but the first URL I send via a browser requires a username and password. Subsequent URLs work without authentication.

I want to use Python within Indigo, to send a URL to the cam, so that I can make controls on my Indigo Video control page that will do things like turn on/off the IR lights, or move the cam to preset positions, or zoom, etc. Something like this:

# where xxx.xxx.xxx.xxx is my cam's local IP address

Code: Select all
import requests
requests.get('http://myUserName:myPassword@xxx.xxx.xxx.xxx/and-then-my-cams-specific-commands-and-parameters-etc')

That doesn't work. So I poked around and found some Python authentication stuff, like this:

Code: Select all
import requests
from requests.auth import HTTPBasicAuth
requests.get('http://xxx.xxx.xxx.xxx/and-then-my-cams-specific-commands-and-parameters-etc', auth=HTTPBasicAuth('myUserName', 'myPassword'))

Which also doesn't work.

I've also tried using "curl" in Terminal, to get a command line string that I could then call from AppleScript or Python within Indigo, and I can't get that to authenticate, either.

Ideas?

Posted on
Thu Oct 31, 2019 10:53 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Sending URLs with authentication

Are you sure it's using basic HTTP authentication? You might want to try digest authentication which is much more secure.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Oct 31, 2019 11:11 am
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Sending URLs with authentication

Thanks Jay. I don't know what any of that means! :lol:

I use Keyboard Maestro (KM). And KM can send this type of URL to my cam with no issues:

Code: Select all
http://myUserName:myPassword@xxx.xxx.xxx.xxx/and-then-my-cams-specific-commands-and-parameters-etc


I asked KM's developer and his software is using "NSURLSession, dataTaskWithURL" to send that URL, which works great, without any additional authentication. Does that mean anything to you?

An additional clue: when I enter that URL format in Safari (with the "username:password@" component), Safari still puts up the cam's web server's authentication interface (where I have to enter the username and password). But when I enter that same URL in Chrome, the resulting page is just the word "OK", and the camera reacts instantly. So passing the username and password embedded in the URL works in Chrome, and Keyboard Maestro, but not in Indigo (using Python) or the Terminal (using curl) or in Safari.

Does that sound like HTTP authentication?

Posted on
Thu Oct 31, 2019 12:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Sending URLs with authentication

Yes, that's the standard HTTP authentication dialog. It usually means either basic or digest. Since you've tried basic, then it's likely digest auth. In your Python script, use HTTPDigestAuth rather than HTTPBasicAuth and it will probably work.

Some browsers support sending the username & password with the URL even for digest auth (even though I think that's technically incorrect), other browsers don't support it and will require you to fill out the authentication dialog they present.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Oct 31, 2019 12:55 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Sending URLs with authentication

Holy Authorization Jayman! That did indeed work! Thanks so much. That's going to save me a lot of trouble!! :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests