skydiver / ewelink-api

eWeLink API for JavaScript
https://www.npmjs.com/package/ewelink-api
MIT License
264 stars 108 forks source link

FetchError: invalid json response body #135

Open BerndKaeseler opened 3 years ago

BerndKaeseler commented 3 years ago

I have the following error:

"FetchError: invalid json response body at https://eu-api.coolkit.cc:8080/api/user/login reason: Unexpected token < in JSON at position 0"

I have Node-Red running via IOBroker. I installed the ewelink-contrib via the palette management of Node-Red.

Unfortunately, I can only get about 6 power state nodes online. So when I try to use 20 nodes from ewelink, only about 6 remain online. The rest are offline, with the error message I inserted above.

It is also not clear which are online and offline, this changes after small changes and a deploy. There are no wrong settings and all hardware devices are actually reachable.

I can't find this file. mixins/makeRequest.js

I am using FileZilla and have searched the entire Pi. Can anyone help me? Where and what I need to change.

Thanks a lot

BerndKaeseler commented 3 years ago

I bought the Advanced Plan from Ewelink for $9.99 per year. No change. It only works with a limited number of nodes. I have also written to Ewelink now, if I can solve the problem, I will still write the solution here.

So to all don't buy Advanced Plan, it doesn't help.

michaelbeljaars commented 3 years ago

I have the same problem. I suspect something goes wrong when Nodered creates more than 6 api connections simultaneously. I am not sure if this is a limitation of the node or of the ewelink api.

michaelbeljaars commented 3 years ago

Not sure why you are looking for the file makeRequest.js but you can find it here: /home/pi/.node-red/node_modules/ewelink-api/src/mixins

JPOLgit commented 2 years ago

I have same problem as well.

Only 6 nodes will connect, with the same behaviour as described by @BerndKaeseler:

"FetchError: invalid json response body at https://eu-api.coolkit.cc:8080/api/user/login reason: Unexpected token < in JSON at position 0"

I wonder whether you have made any progress in diagnosing this issue?

Thank you for the useful advice to avoid trying to solve it via advanced plan etc.

Pool0513 commented 2 years ago

Hello, I also have the exact same issue. Only 6 nodes will connect. To connect my other nodes I'll have to stop start each nodes many time until they connect. Sometimes it work but most of the time it doesn't. This is really frustrating cause your api is amazing... The error is : [error] [ewelink-power-state-write:LED Switch] FetchError: invalid json response body at https://eu-api.coolkit.cc:8080/api/user/login reason: Unexpected token < in JSON at position 0.

I have found this thread with someone speaking about this issue and having a working solution : https://github.com/skydiver/ewelink-api/issues/116

he said :

I add this code to mixins/makeRequest.js after line 42, because the API ramdomly answer with a crazy html shop code. Maybe is a bad solution but works for me.

let request = await fetch(requestUrl, payload); let contentType = request.headers.get("content-type");

while(!(contentType && contentType.indexOf("application/json") !== -1)) { request = await fetch(requestUrl, payload); contentType = request.headers.get("content-type"); }

I have tried his solution with no luck.

Please help :)

JPOLgit commented 2 years ago

I have 'given up' so to speak and flashed all my sonoffs across to tasmota... Much easier to do than I had anticipated and I am very happy to have taken the plunge.