delian / node-unifiapi

UniFi API ported to Node.JS
GNU General Public License v3.0
49 stars 19 forks source link

Error { data: [], meta: { msg: 'api.err.LoginRequired', rc: 'error' } } #3

Closed seanmavley closed 6 years ago

seanmavley commented 7 years ago

After the server keeps running for a while, making a request returns the error:

Error { data: [],
  meta: { msg: 'api.err.LoginRequired', rc: 'error' } }

A simple workaround I'm thinking of is logging in per each transaction.

That's the right way? Or there's a setting somewhere I'm missing?

delian commented 7 years ago

Which version is that? I could make it if it see loginrequired to automatically try to repeat the last login and then to repeat the call?

On Thu, May 25, 2017, 00:19 Nkansah Rexford notifications@github.com wrote:

After the server keeps running for a while, making a request returns the error:

Error { data: [], meta: { msg: 'api.err.LoginRequired', rc: 'error' } }

A simple workaround I'm thinking of is logging in per each transaction.

That's the right way? Or there's a setting somewhere I'm missing?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/delian/node-unifiapi/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AAG7Zv7YEGfA0Mo7NGrlxXKTwzAMsvF2ks5r9Kz_gaJpZM4NlvQE .

seanmavley commented 7 years ago

My unifi controller is 5.4.15 I'm using Node 7 (I don't know if that matters) And using the latest of node-unifiapi

This is what I did, by attempting to login each time, however it still brings up the same error: https://github.com/seanmavley/unifi-guest-bundle-check/commit/5f27aa9544996f956afee7ed8776899886d5e129#diff-bb503f3d9047bcd4a5730559f1e16560R59

I could make it if it see loginrequired to automatically try to repeat the last login and then to repeat the call?

I don't know if that'll fix it, but if so, that'll be great.

delian commented 7 years ago

I actually happened to have such a code. Within lib/unifi-request.js there is a line:

if ((resp && resp.statusCode == 401) || (typeof error == 'string' && error.match('api.err.LoginRequired'))) {

.. and then it retry the connection once (because it will become a forever loop if it retry forever because of wrong credentials or anything else wrong)

Maybe there is an error in my algorithm or a bug, or you use a different code.

Would it be possible for you to send me the following info:

1) What version of the node-unifiapi you use (npm ls node-unifiapi) and if it is not 0.44 please upgrade to 0.44 and retry again? 2) Send me sample of your code you use to connect (so I can see how do you initialize it, may be there is a bug in the package that depends on the way how it is used), please replace the credentials with something else, I dont need them

3) Send me a debug output (you can enable it, by setting debug: true and debugNet: true in the initialization options), you can also replace the credentials in the debug with something different, I just want to see if/when it has seen the err.loginRequired it has retried to login and it has done it with the correct credentials

On Thu, May 25, 2017 at 11:17 AM Nkansah Rexford notifications@github.com wrote:

My unifi controller is 5.4.15 I'm using Node 7 (I don't know if that matters) And using the latest of node-unifiapi

This is what I did, by attempting to login each time, however it still brings up the same error: seanmavley/unifi-guest-bundle-check@5f27aa9

diff-bb503f3d9047bcd4a5730559f1e16560R59

https://github.com/seanmavley/unifi-guest-bundle-check/commit/5f27aa9544996f956afee7ed8776899886d5e129#diff-bb503f3d9047bcd4a5730559f1e16560R59

I could make it if it see loginrequired to automatically try to repeat the last login and then to repeat the call?

I don't know if that'll fix it, but if so, that'll be great.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/delian/node-unifiapi/issues/3#issuecomment-303963389, or mute the thread https://github.com/notifications/unsubscribe-auth/AAG7Zk_VKg-gB5I_wuMYeclyey-N1VQAks5r9UckgaJpZM4NlvQE .

seanmavley commented 7 years ago

Thanks for getting in touch.

1) Here's my node-unifiapi version:

khophi:UnifiGuest$ npm ls node-unifiapi
unifiguest@0.0.0 /home/khophi/Developments/Express/UnifiGuest
└── node-unifiapi@0.0.45 

The only available versions in npm for node-unifapi is 0.0.45, 0.0.44, 0.0.40, 0.0.39, 0.0.38, 0.0.37, 0.0.36, thus I think I have the latest which is 0.0.45.

2) This is what is Use to connect: https://github.com/seanmavley/unifi-guest-bundle-check/blob/master/routes/index.js#L59-L76

And this my credentials: https://github.com/seanmavley/unifi-guest-bundle-check/blob/master/routes/index.js#L59-L76

3) Sorry, when I enable debug, I don't see any log messages anywhere, no error logs in console, except the Error { data: [], meta: { msg: 'api.err.LoginRequired', rc: 'error' } }

When I enable the debug where should I see the logs?

seanmavley commented 7 years ago

So it seems to be working. Per each transaction, I logout at the end. Thus, any next transaction needs to reauthenticate. Which seems to be working pretty as expected.

I do not know the down side to doing it that way, but at least it gets it working for now.

seanmavley commented 6 years ago

Could you look into this? Explicitly logging out per each transaction doesn't solve the problem in the long run. Still throws the error:

Error { data: [],
  meta: { msg: 'api.err.LoginRequired', rc: 'error' } }