Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid json response body #116

Closed
apadilla83 opened this issue Oct 30, 2020 · 5 comments
Closed

invalid json response body #116

apadilla83 opened this issue Oct 30, 2020 · 5 comments

Comments

@apadilla83
Copy link

I get this error some times when use getDevicePowerState

g: FetchError: invalid json response body at https://eu-api.coolkit.cc:8080/api/user/device/status?deviceid=10007df37d&appid=YzfeftUVcZ6twZw1OoVKPRFYTrGEg01Q&nonce=uf1lhtn&ts=1604043174&version=8&params=switch%7Cswitches reason: Unexpected token < in JSON at position 0
at /usr/src/node/node_modules/ewelink-api/node_modules/node-fetch/lib/index.js:272:32

Thanks!

@adrianrguez
Copy link

adrianrguez commented Oct 30, 2020

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");
}

Captura de pantalla de 2020-10-30 16-43-23@2x

@apadilla83
Copy link
Author

apadilla83 commented Nov 1, 2020

Ok thanks I will test it!

@apadilla83
Copy link
Author

Work Great!

@adrianrguez
Copy link

I’m very happy it work!! Maybe the fix must be included in the oficial code. How?

@BerndKaeseler
Copy link

I'm writing here because I think my problem could fit in here.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants