So I am trying to use the system.net.httpGet function to return the saftware version of my IP camera(s). I keep getting a 401 error response and am uncertain as to why.
url = "http://IPAddressofCamera/cgi-bin/magicBox.cgi?action=getSoftwareVersion"
user = 'username'
passwd = 'password'
vers = system.net.httpGet(url, username=user, password=passwd)
And the response looks like:
Traceback (most recent call last):
File "<input>", line 5, in <module>
IOError: Server returned HTTP response code: 401 for URL: http://IPAddressofCamera/cgi-bin/magicBox.cgi?action=getSoftwareVersion
When I enter the same address into chrome, it asks for username and password, to which I enter the same user and password as the code. Once this is completed, it displays a webpage with the information I would expect.
Does anyone have any idea as to what could be the problem here?
Since this is less a post about Ignition and more a post about REST communication, my recommendation would be to use a free tool like PostMan ( https://www.postman.com/ ) to make sure you get your REST calls right. It has a nice interface that lets you test communication intended exactly for working out this type of request. After you have that working, then you can throw the right settings and options into Ignition’s httpClient() call.
In your requests you might end up needing to set some cookies, pass in authentication using something other than HTTP Basic Auth (using a post possibly with form data, and getting back a token, for example). If you want to watch how the browser does it, you can open up Chrome’s Dev Tools ( Ctrl-Shift-I ) and watch the Network tab. It has details on the headers and data in the requests and responses.
@Kuskah, were you able to solve your issue? I’m running into the same problem with my cameras due to an unsecure http secondary message. Any insight into your solution would be greatly appreciated. Thanks