SondreNjaastad / node-red-contrib-bluelinky

20 stars 7 forks source link

HTTPError: Response code 401 (Authorization Required) #4

Closed NellicusLabs closed 4 years ago

NellicusLabs commented 4 years ago

Attempting to configure a flow to get status and receive "HTTPError: Response code 401 (Authorization Required)" as a debug output. This is the US region.

Screen Shot 2020-05-14 at 11 19 06 AM Screen Shot 2020-05-14 at 11 18 29 AM
SondreNjaastad commented 4 years ago

What version of the node red lib are you using?

NellicusLabs commented 4 years ago

Node-Red: 1.0.6 Bluelinky: 0.0.6-alpha

SondreNjaastad commented 4 years ago

Thanks, are you able to read out the logs from node-red? And are you able to log into the app at this moment?

NellicusLabs commented 4 years ago

I was able to login via the mobile app and website and issue commands. I have Node-Red set to debug log. Below is the output:

Started Node-RED graphical event wiring tool. 14 May 11:58:27 - [info] Welcome to Node-RED 14 May 11:58:27 - [info] Node-RED version: v1.0.6 14 May 11:58:27 - [info] Node.js version: v10.20.1 14 May 11:58:27 - [info] Linux 4.15.0-99-generic x64 LE 14 May 11:58:27 - [info] Loading palette nodes 14 May 11:58:28 - [debug] Module: node-red-contrib-bigtimer 2.3.1 14 May 11:58:28 - [debug] /home/homeassistant/.node-red/node_modules/node-red-contrib-bigtimer 14 May 11:58:28 - [debug] Module: node-red-contrib-bluelinky 0.0.6-alpha 14 May 11:58:28 - [debug] /home/homeassistant/.node-red/node_modules/node-red-contrib-bluelinky 14 May 11:58:28 - [debug] Module: node-red-contrib-home-assistant-websocket 0.22.3 14 May 11:58:28 - [debug] /home/homeassistant/.node-red/node_modules/node-red-contrib-home-assistant-websocket 14 May 11:58:28 - [debug] Module: node-red-contrib-light-scheduler 0.0.15 14 May 11:58:28 - [debug] /home/homeassistant/.node-red/node_modules/node-red-contrib-light-scheduler 14 May 11:58:28 - [debug] Module: node-red-node-rbe 0.2.8 14 May 11:58:28 - [debug] /usr/lib/node_modules/node-red/node_modules/node-red-node-rbe 14 May 11:58:28 - [debug] Module: node-red-node-tail 0.1.1 14 May 11:58:28 - [debug] /usr/lib/node_modules/node-red/node_modules/node-red-node-tail 14 May 11:58:30 - [info] Settings file : /home/homeassistant/.node-red/settings.js 14 May 11:58:30 - [info] Context store : 'default' [module=memory] 14 May 11:58:30 - [info] User directory : /home/homeassistant/.node-red 14 May 11:58:30 - [warn] Projects disabled : editorTheme.projects.enabled=false 14 May 11:58:30 - [info] Flows file : /home/homeassistant/.node-red/flows_homeassistant.json 14 May 11:58:30 - [debug] loaded flow revision: 39367f5c637e8cc150741b7de2962c69 14 May 11:58:30 - [debug] red/runtime/nodes/credentials.load : user provided key 14 May 11:58:30 - [debug] red/runtime/nodes/credentials.load : keyType=user 14 May 11:58:30 - [info] Starting flows 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : global 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : 9895e5bc.3041a8 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : ac4c6aa6.2a2fd8 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : ad453f81.1940f8 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : e6281f27.bac418 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : da25b803.d7c14 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : 5d3f7d5e.c70e34 14 May 11:58:30 - [debug] red/nodes/flows.start : starting flow : 91619d6f.570d78 14 May 11:58:30 - [debug] [server:Home Assistant] instantiated node, name: Home Assistant [2020-05-14 11:58:30] info: US Controller created [2020-05-14 11:58:30] info: Bluelinky is loging in automatically, to disable use autoLogin: false 14 May 11:58:30 - [info] Started flows 14 May 11:58:30 - [info] Server now running at http://127.0.0.1:1880/ [2020-05-14 11:58:32] info: US Vehicle {REDACTEDVIN} created [2020-05-14 11:58:32] info: US Vehicle {REDACTEDVIN} created

SondreNjaastad commented 4 years ago

Thanks. So from here i have to talk to @Hacksore , as I live in EU and the code is quite diffrent.

[2020-05-14 11:58:32] info: US Vehicle {REDACTEDVIN} created   
[2020-05-14 11:58:32] info: US Vehicle {REDACTEDVIN} created

Are these 2 diffrent cars or does it log the same car twice?

NellicusLabs commented 4 years ago

They are two different vehicles on my account. Each show the unique vin for each vehicle.

SondreNjaastad commented 4 years ago

Cool! I think you are the first person to have multiple cars testing Bluelinky. So maybe that has something to do with the issues. (Note to @Hacksore )

Hacksore commented 4 years ago

Maybe we can have @justinoreilly try and use the debug.js feature of bluelinky to isolate the issue outside of node-red.

What you need to do:

  1. git clone https://github.com/Hacksore/bluelinky.git
  2. npm run build
  3. create config.json in the root of the bluelinky directory, example:
    {
    "username": "",
    "password": "",  
    "pin": "",
    "vin": ""
    }
  4. node debug.js
  5. US -> status (on bluelink cache)
  6. Expect a status from the first vehicle
NellicusLabs commented 4 years ago

Here is the output:

{"errorSubCode":"IDM_401_4","functionName":"remoteVehicleStatus","errorSubMessage":"Feature disabled as it is not part of subscription.","errorMessage":"Feature disabled as it is not part of subscription.","errorCode":401}

I have 2 vehicles on my account. One of them has an inactive BlueLink subscription (first one ever added to my account) and the second one has an active BlueLink subscription. Based on this error, It looks like it is trying to use the opposite VIN from which I am specifying in the config file but rather the first vehicle in the account which does not have an active subscription.

Hacksore commented 4 years ago

@justinoreilly If you edit debug.js you can do this to select the second vehicle, we are not using the config vin to pull the correct vehicle.

image

NellicusLabs commented 4 years ago

That worked in debug. I was able to get the status of the correct vehicle. Any idea how/when this could be integrated to work with the flows?

SondreNjaastad commented 4 years ago

The issue might be this function;

https://github.com/SondreNjaastad/node-red-contrib-bluelinky/blob/3f36c0621dbf90cc0de764fff012a88eda8e1ad6/bluelinky.js#L56

With the debug.js tests above, you go around that function.

you can edit the line in onReadyHandler to;

vehicle = client.getVehicle('YOUR VIN');

That is a more accurate test

SondreNjaastad commented 4 years ago

Potential issue:

https://github.com/Hacksore/bluelinky/blob/029efe5aa2aadaa4cdc29226763edc61562bba63/lib/index.ts#L91

NellicusLabs commented 4 years ago

I am not quite sure I follow. Edit my copy of bluelinky.js? /home/homeassistant/.node-red/node_modules/node-red-contrib-bluelinky/bluelinky.js Change (line 12) const car = await client.getVehicle(this.bluelinkyConfig.vin); to let car = await client.getVehicle('XXXXXMYVINXXXXXXX');

And this should for now manually select the correct vehicle?

SondreNjaastad commented 4 years ago

No, sorry, poor explanation, i only refrenced that to show what i was thinking.

The edit should be done in debug.js, the same line you edited from [0] to [1] should be (the whole line)

vehicle = client.getVehicle('YOUR VIN');

No need to change anything on the bluelinky lib

NellicusLabs commented 4 years ago

Changing that line in debug.js resulted in the following:

vehicle = vehicles[1]; to vehicle = client.getVehicle('YOUR VIN');

(node:2602) UnhandledPromiseRejectionWarning: ReferenceError: client is not defined at e.onReadyHandler (/home/homeassistant/.node-red/bluelinky/debug.js:24:3) at emit (events.js:198:13) at e. (/home/homeassistant/.node-red/bluelinky/dist/index.js:1:35580) at /home/homeassistant/.node-red/bluelinky/dist/index.js:1:2098 at Object.next (/home/homeassistant/.node-red/bluelinky/dist/index.js:1:2203) at n (/home/homeassistant/.node-red/bluelinky/dist/index.js:1:936) at process._tickCallback (internal/process/next_tick.js:68:7) (node:2602) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:2602) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

SondreNjaastad commented 4 years ago

Change

https://github.com/Hacksore/bluelinky/blob/029efe5aa2aadaa4cdc29226763edc61562bba63/debug.js#L53

to

client = new BlueLinky({

and add

let client = null;

To line 8

NellicusLabs commented 4 years ago

Here is what I have for debug.js so far. https://gist.github.com/justinoreilly/3cacaef9cc37e9f3e5e91766a1206275

SondreNjaastad commented 4 years ago

Perfect, now run that for both cars

SondreNjaastad commented 4 years ago

This issue was in Bluelinky, and was resolved in 4.2.1. Lib was updated in release 0.0.8-alpha

jdfrey1 commented 3 years ago

I am getting this error often as well as well and it seems that the only fix to it is to reDeploy or restart my flows. The error occurs immediately when the car-location node is enabled. It seems to fail when I'm not currently displaying node-red and then when I return the only way to get it to work again is to restart the flow. I'm trying to update my vehicle position every hour and then also when I arrive at home but. I'm currently using node-red-contrib-bluelinky v0.0.15.

node-red