NEWS
axios Abfragen funktioniet nicht mehr
-
ich habe ein Problem. Ich habe den JavaScript Adapter auf die aktuelle Version 5.2.21 hochgezogen.
Leider laufen seit dem meine Javascripte mit Axios nicht mehr. Kann mir jemand helfen wo mein Problem ist?
Log:
javascript.0 2022-01-19 21:37:43.757 error at Script.runInContext (vm.js:130:18) javascript.0 2022-01-19 21:37:43.757 error at script.js.Test.axios_test2:130:3 javascript.0 2022-01-19 21:37:43.757 error at script.js.Test.axios_test2:128:5 javascript.0 2022-01-19 21:37:43.757 error at func_Version (script.js.Test.axios_test2:38:5) javascript.0 2022-01-19 21:37:43.757 error at wrap (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/helpers/bind.js:9:15) javascript.0 2022-01-19 21:37:43.756 error at Axios.request (/opt/iobroker/node_modules/iobroker.javascript/node_modules/axios/lib/core/Axios.js:40:11) javascript.0 2022-01-19 21:37:43.756 error script.js.Test.axios_test2: Error: Provided config url is not valid
Das Script:
const logging = true; const debugging = false; const debugging_response = false; //nur im Fehlerfall auf true. Hiermit wird die Antwort der Internetadresse protokolliert let Serial = 'NEQ7777777' //der eigenen CCU eintragen (nur relevant für ccu2 und 3) let CCU_Version = 2; //Hier eine Zahl eintragen: 2 = CCU2 // 3 = CCU3 // 4 = Rasperrymatic // 5= pivccu2 lastest //= 6 pivccu3 latest // 7 = debimatic = latest bzw 51, 61 bzw 71 für die jeweilige Testing Version const observation = true; //Dauerhafte Überwachung der Firmware (true = aktiv // false =inaktiv) const onetime = true; //Prüft beim Scriptstart auf aktuelle Firmware //Prio für Pushover const prio_Firmware = 0; // **************************** ab hier keine Änderung ********************************************************* let _message_tmp; function func_Version(){ //const ccu2 = 'http://update.homematic.com/firmware/download?cmd=js_check_version&version=12345&product=HM-CCU2&serial=12345'; const ccu2 = 'https://update.homematic.com/firmware/download?cmd=js_check_version&version=2.22.22&product=HM-CCU2&serial=NEQ7777777'; let url = ccu2; const axios = require('axios'); axios({ method: 'get', baseURL: url, timeout: 4500, responseType: 'json' }) .then((response) => { if(debugging){ console.log('data:' +response.data); console.log('Status: ' +response.status); console.log('Header:' +response.headers); } if(response.status = 200){ //Umwandeln in String var data_string = JSON.stringify(response.data) //1. Split //var data_split= data_string.split("{"); //Unnötige Sachen entfernen //var data_replace = data_split[2].replace(/}|,|]|:/gi,''); //mit 2. Split zum Ergebnis //var data_final = data_replace.split('"'); //Ergebnisse //var _Status = parseInt(data_final[2],10); //var _Helligkeit = parseInt(data_final[4],10); //var _Temperatur = parseInt(data_final[6],10); //log('[DEBUG] ' +'Typ body: ' +typeof body); const Version = data_string.split("'"); //log('[DEBUG] ' +'Typ Version: ' +typeof Version); //Fehler finden if(debugging){ log('[DEBUG] ' +'Typ body: ' +typeof data_string); log('[DEBUG] ' +'Typ Version: ' +typeof Version); log('[DEBUG] ' +'Typ Version1: ' +typeof Version[1]); log('[DEBUG] ' +'Typ Version2: ' +typeof Version[2]); log('[DEBUG] ' +'Typ Version3: ' +typeof Version[3]); } if(debugging){ log('[DEBUG] ' +'Version aus URL: '+Version[1]); log('[DEBUG] ' +'Name aus URL für Version: '+Version[3]); } if(debugging_response){ log('body: ' + data_string); log('Länge ' + Version.length + ' --- Version: ' + Version[1]); log('response: ' + JSON.stringify(response)); } } else{ if(logging){ log('Hier stimmt etwas nicht. Meldung: '+response.status) } } }) .catch( (error) => { // handle error log('Fehler bei der Abfrage der Firmware: '+error,'warn'); } ); } if(onetime){ //beim Starten func_Version(); }
-
Mit folgenden Script geht es:
const logging = true; const debugging = true; const debugging_response = true; //nur im Fehlerfall auf true. Hiermit wird die Antwort der Internetadresse protokolliert let Serial = 'NEQ7777777' //der eigenen CCU eintragen (nur relevant für ccu2 und 3) let CCU_Version = 2; //Hier eine Zahl eintragen: 2 = CCU2 // 3 = CCU3 // 4 = Rasperrymatic // 5= pivccu2 lastest //= 6 pivccu3 latest // 7 = debimatic = latest bzw 51, 61 bzw 71 für die jeweilige Testing Version const onetime = true; //Prüft beim Scriptstart auf aktuelle Firmware // **************************** ab hier keine Änderung ********************************************************* async function func_Version(){ const ccu2 = 'https://update.homematic.com/firmware/download?cmd=js_check_version&version=2.22.22&product=HM-CCU2&serial=NEQ7777777'; let url = ccu2; const axios = require('axios').default; try{ let res = await axios.get(url, {timeout: 4500, responseType: 'json' } ) var data_string = JSON.stringify(res.data) const Version = data_string.split("'"); if(debugging){ log('[DEBUG] ' +'Typ body: ' +typeof data_string); log('[DEBUG] ' +'Body: '+data_string); log('[DEBUG] ' +'data:' +res.data); log('[DEBUG] ' +'Status: ' +res.status); log('[DEBUG] ' +'Header:' +res.headers); log('[DEBUG] ' +'Typ Version: ' +typeof Version); log('[DEBUG] ' +'Typ Version1: ' +typeof Version[1]); log('[DEBUG] ' +'Typ Version2: ' +typeof Version[2]); log('[DEBUG] ' +'Typ Version3: ' +typeof Version[3]); log('[DEBUG] ' +'Version aus URL: '+Version[1]); log('[DEBUG] ' +'Name aus URL für Version: '+Version[3]); } //return res.status === 200 ? true : false; } catch (e) { log('Fehler: '+e) //var status; //return status = false; } } if(onetime){ //beim Starten func_Version(); }
Nun komme ich aber bei einen anderen Script nicht weiter. Wie bringe ich folgenden Code unter:
const axios = require('axios'); axios({ method: 'put', baseURL: 'http://192.168.178.75:9123/elgato/lights', headers: {'Content-Type':'application/x-www-form-urlencoded'} , data: { "lights":[{ "brightness":Brightness_Key_Light_1, "temperature":Temperature_Key_Light_1, "on":1}], "numberOfLights":1 }, timeout: 4500, responseType: 'json' }) .then((response) => {
Gehört zu einen anderen Script wo ich eine elgato Keylight schalte.
ich muss irgendwie in
try{ let res = await axios.put(url, {timeout: 4500, responseType: 'json' } )
noch das unterbringen:
headers: {'Content-Type':'application/x-www-form-urlencoded'} , data: { "lights":[{ "brightness":Brightness_Key_Light_1, "temperature":Temperature_Key_Light_1, "on":1}], "numberOfLights":1 },
-
@cash Ich glaub dein Fehler ist viel einfacher:
baseURL: url,
müsste einfach nururl: url,
(oderurl,
) lauten. So steht's nämlich auch in der Doku! -
@alcalzone wie peinlich. Ja damit geht es wieder. Vorher hat baseURL aber auch funktioniert.