Getting authorization error when running Piston


#1

1) Give a description of the problem
I’m a newbie to webcore and I am not a developer. I am trying to create a piston which sends a URL to my IP camera to turn motion detection on when both my wife’s and my iPhone presence sensors are not present. When I manually issue the URL using my safari browser it works fine. When I test the piston i get the following error:

“Error executing external web request: groovyx.net.http.HttpResponseException: Unauthorized|”

I’ve researched everything I can find that is similar, but I’m having no luck implementing a solution.

2) What is the expected behavior?
(PUT YOUR INFO HERE)

3) What is happening/not happening?
|+559ms|║║Error executing external web request: groovyx.net.http.HttpResponseException: Unauthorized|

4) Post a Green Snapshot of the piston

5) Attach any logs (From ST IDE and by turning logging level to Full)

+0ms ╔Received event [Beach House].test = 1520945559025 with a delay of 1ms
+104ms ║RunTime Analysis CS > 17ms > PS > 49ms > PE > 38ms > CE
+107ms ║Runtime (38571 bytes) successfully initialized in 49ms (v0.3.000.20180224) (105ms)
+107ms ║╔Execution stage started
+120ms ║║Comparison (enum) not present is (string) not present = true (1ms)
+121ms ║║Condition #7 evaluated true (9ms)
+122ms ║║Condition group #6 evaluated true (state did not change) (10ms)
+130ms ║║Comparison (enum) not present is (string) not present = true (1ms)
+131ms ║║Condition #8 evaluated true (8ms)
+132ms ║║Condition group #1 evaluated true (state did not change) (20ms)
+134ms ║║Cancelling statement #4’s schedules…
+143ms ║║Sending external web request to: xx.xx.xx.xx:xxxx/form/setMotion?WINDOW=1&ENABLE=1&LEFT=0&TOP=0&RIGHT=639&BOTTOM=479&THRESHOLD=46&SENSITIVITY=46
+466ms ║║Error executing external web request: groovyx.net.http.HttpResponseException: Unauthorized
+467ms ║║Executed virtual command httpRequest (329ms)
+471ms ║╚Execution stage complete. (363ms)
+472ms ╚Event processed successfully (472ms)

#2

You may need to add the Authorization Header to your GET request.
Authorization header (optional):
type (Value):
“Basic xxxxxxxx” where “xxxxx” is a Base64 encoded username/password (https://www.blitter.se/utils/basic-authentication-header-generator/)

Here’s an example from one of my pistons where it grabs info from my local router which requires authorization:


#3

What kind of IP camera? I’m using an Amcrest IP2M-841 and it requires digest authentication. The only way (so far) to make that work (with a webCoRE “Make a web request”) is to use an external IP address (i.e., not a LAN address, which would go directly from the ST Hub to the camera, but rather from the ST Cloud, through your router and on to the camera.) See Support for digest authentication with web requests using internal addresses.

Also, I haven’t gotten HTTPS to work (with ST) because the camera uses a self generated certificate that does not use a root certificate authority that the ST Cloud knows about. (And, unlike with a browser, you can’t tell ST to continue anyway, at least as far as I know about.)

So, bottom line, you need to use an URL like this: “http://username:password@external_ip_address:external_port_number/…”, where username and password are the credentials for the camera.


#4

Thanks for the quick response. The link for the basic authentication header generator you referenced prompts me for a username and password. Is this suppose to be the username and password that I am trying to pass in my URL statement? I am a little confused on how I get the necessary basic authentication header to include in my GET.


#5

That’s correct, you just enter the username/password combo, and it’ll generate the authorization header for you, which will result in “Basic xxxxlkjdflsjfd” or something similar…


#6

That did the trick, thanks so much for the help!


#7

I’m using a Sharx 2900 camera and it will accept the external web address. The URL I am sending looks exactly like you identified, but apparently it needed the basic authentication header from the generator allrak identified in his response. I used the username and password from my URL command to generate the basic authentication header from the link (https://www.blitter.se/utils/basic-authentication-header-generator/). I copied the generated authentication header and pasted it into the Authorization (optional) field for a value and that solved my problem.


#8

As I said, I’m using an Amcrest camera, and they switched to digest authentication at some point in the recent past (before I got my camera.) Other cameras apparently use basic authentication. That’s why I asked.

In either case, if you’re using an external address and port (i.e., the traffic goes between the ST cloud and your camera through your router, not from your ST hub to the camera directly on your LAN), then you can just use an URL that includes the username and password (e.g., something like “http://username:[email protected]/…”) and the ST network layers will translate that to a basic authentication header, or a digest authentication header if the camera requires it. (Note that webCoRE makes different ST calls depending on whether the URL uses a LAN address or an external address.) It will all happen “under the skins”/transparently. I.e., you don’t have to manually convert to Base64 and include the authentication header yourself. However, you can if you like, as long as the camera accepts basic authentication. At least, that’s my understanding.

In any case, I’m glad you got it working! :slight_smile: