Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. Zugangsgeschützte API-Schnittstelle auslesen mit Blockly

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Zugangsgeschützte API-Schnittstelle auslesen mit Blockly

    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      schnipsel71 @OliverIO last edited by

      @oliverio Mit dem alten Beispielscript und dem Request-Befehl funktioniert es seit mindestens zwei Jahren, aber eben seit ca. 2 Monaten nur noch mit folgendem (zweifachen) Warnhinweis im Log alle fünf Sekunden:

      javascript.0
      241772	2024-07-14 16:26:49.736	warn	script.js.Steuerung.Hycube: request package is deprecated - please use httpGet (or a stable lib like axios) instead!
      javascript.0
      241772	2024-07-14 16:26:49.812	warn	script.js.Steuerung.Hycube: request package is deprecated - please use httpGet (or a stable lib like axios) instead!
      

      Natürlich ersetze ich hier im Forum die tatsächliche, lokale IP des Hycube-Gerätes durch "ip".

      1 Reply Last reply Reply Quote 0
      • T
        TT-Tom @schnipsel71 last edited by

        @schnipsel71 lass mal das timeout weg.

        S 1 Reply Last reply Reply Quote 0
        • S
          schnipsel71 @TT-Tom last edited by

          @tt-tom Da kommt nur das zurück:

          javascript.0	17:09:12.076	error	script.js.common.Hycube_TT-Tom: timeout of 2000ms exceeded
          
          T 1 Reply Last reply Reply Quote 0
          • T
            TT-Tom @schnipsel71 last edited by TT-Tom

            @schnipsel71

            habe mir noch mal den Code aus Post 2 angesehen. is nur ein Versuch

            httpGet(
                'http://ip/auth/',
                {
                    headers: {
                    'Authorization': '(Basic hycube:hycube)'
                    },
                },
                (error, response) => {
                    if (!error) {
                        console.log(response.statusCode);
                        console.log(response.data);
                        console.log(response.headers);
                    } else {
                        console.error(error);
                    }
                }
            )
            
            

            oder mal die Klammern beim User:password weglassen.

            OliverIO S 2 Replies Last reply Reply Quote 0
            • OliverIO
              OliverIO @TT-Tom last edited by OliverIO

              @tt-tom sagte in Zugangsgeschützte API-Schnittstelle auslesen mit Blockly:

              oder mal die Klammern beim User:password weglassen.

              es wird immer mehr verschlimmbessert.
              so funktioniert Basic Authentiction nicht.
              Also entweder überlasst ihr das dem httpPost, in dem ihr im configobjekt user und password gemäß der doku angebt. dann erstellt das system für euch den header richtig
              oder ihr erstellt den header selber, dazu muss aber userid und password richtig kodiert werden.
              https://de.wikipedia.org/wiki/HTTP-Authentifizierung#Basic_Authentication
              vergleiche dazu mein Beispiel wo das so gemacht wird.

              Allerdings kommt die Anfrage ja noch gar nicht soweit, da der Server auf die Anfrage ja nicht reagiert und nach timeout die abfrage abgebrochen wird.

              1 Reply Last reply Reply Quote 0
              • S
                schnipsel71 @TT-Tom last edited by

                @tt-tom Jetzt kommt tatsächlich folgende Reaktion im Log:

                javascript.0	19:11:08.887	info	script.js.common.Hycube_TT-Tom: registered 0 subscriptions, 0 schedules, 0 messages, 0 logs and 0 file subscriptions
                javascript.0	19:11:08.923	info	script.js.common.Hycube_TT-Tom: 401
                javascript.0	19:11:08.924	info	script.js.common.Hycube_TT-Tom:
                javascript.0	19:11:08.924	info	script.js.common.Hycube_TT-Tom: Object [AxiosHeaders] { 'access-control-allow-headers': 'Authorization', 'access-control-allow-origin': '*', connection: 'close', 'content-length': '0', 'content-type': 'cty', 'www-authenticate': 'Basic realm="00"' }
                javascript.0	19:11:16.897	info	Stopping script script.js.common.Hycube_TT-Tom
                

                Was fange ich damit jetzt an?

                OliverIO T 2 Replies Last reply Reply Quote 0
                • OliverIO
                  OliverIO @schnipsel71 last edited by OliverIO

                  @schnipsel71

                  401 ist Unautorized

                  https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401
                  vgl dazu mein beitrag von soeben

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    schnipsel71 @OliverIO last edited by schnipsel71

                    @oliverio sagte in Zugangsgeschützte API-Schnittstelle auslesen mit Blockly:

                    @schnipsel71

                    401 ist Unautorized

                    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401
                    vgl dazu mein beitrag von soeben

                    Danke für die Info.
                    Immerhin aber wenigstens mal ein Lebenszeichen.

                    Wie kann ich denn nun aber ganz konkret die Authentifizierung richtig durchführen?

                    Hier mal das API-Manual vom Hycube-System:
                    hycube API_Manual.pdf

                    OliverIO 1 Reply Last reply Reply Quote 0
                    • T
                      TT-Tom @schnipsel71 last edited by

                      @schnipsel71

                      Probiere mal das.

                      httpGet(
                          'http://ip/auth/',
                          {
                              headers: {
                              "Authorization": Buffer.from("Basic hycube:hycube").toString(’base64’)
                              },
                          },
                          (error, response) => {
                              if (!error) {
                                  console.log(response.statusCode);
                                  console.log(response.data);
                                  console.log(response.headers);
                              } else {
                                  console.error(error);
                              }
                          }
                      )
                       
                      
                      
                      OliverIO S 2 Replies Last reply Reply Quote 0
                      • OliverIO
                        OliverIO @schnipsel71 last edited by

                        @oliverio sagte in Zugangsgeschützte API-Schnittstelle auslesen mit Blockly:

                        Also entweder überlasst ihr das dem httpPost, in dem ihr im configobjekt user und password gemäß der doku angebt. dann erstellt das system für euch den header richtig

                        httpGet(
                            'http://ip/auth/',
                            null,
                            {
                                basicAuth: {
                                    user: 'hycube',
                                    password: 'hycube'
                                }
                            },
                            (error, response) => {
                                if (!error) {
                                    console.log(response.statusCode);
                                    console.log(response.data);
                                    console.log(response.headers);
                                } else {
                                    console.error(error);
                                }
                            }
                        );
                        
                        S 1 Reply Last reply Reply Quote 0
                        • OliverIO
                          OliverIO @TT-Tom last edited by OliverIO

                          @tt-tom sagte in Zugangsgeschützte API-Schnittstelle auslesen mit Blockly:

                              "Authorization": Buffer.from("Basic hycube:hycube").toString(’base64’)
                          

                          leider auch nicht. Basic soll nicht mit codiert werden.

                          "Authorization": "Basic " + Buffer.from("hycube:hycube").toString(’base64’)
                          

                          Ist lustigerweise im Herstellerbeispiel auch falsch
                          Besser ist aber über config-objekt

                          1 Reply Last reply Reply Quote 0
                          • S
                            schnipsel71 @TT-Tom last edited by schnipsel71

                            @tt-tom Dieser Code:

                            httpGet(
                                'http://ip/auth/',
                                {
                                    headers: {
                                    "Authorization": "Basic " + Buffer.from("hycube:hycube").toString(’base64’)
                                    },
                                },
                                (error, response) => {
                                    if (!error) {
                                        console.log(response.statusCode);
                                        console.log(response.data);
                                        console.log(response.headers);
                                    } else {
                                        console.error(error);
                                    }
                                }
                            )
                            

                            ergibt folgenden Fehler:

                            javascript.0	20:13:06.962	info	Start JavaScript script.js.common.Hycube_TT-Tom (Javascript/js)
                            javascript.0	20:13:06.963	error	script.js.common.Hycube_TT-Tom compile failed: at script.js.common.Hycube_TT-Tom:6
                            

                            ...scheint also nur ein syntaktischer Fehler zu sein...

                            1 Reply Last reply Reply Quote 0
                            • S
                              schnipsel71 @OliverIO last edited by schnipsel71

                              @oliverio Dieser Code:

                              httpGet(
                                  'http://ip/auth/',
                                  null,
                                  {
                                      basicAuth: {
                                          user: 'hycube',
                                          password: 'hycube'
                                      }
                                  },
                                  (error, response) => {
                                      if (!error) {
                                          console.log(response.statusCode);
                                          console.log(response.data);
                                          console.log(response.headers);
                                      } else {
                                          console.error(error);
                                      }
                                  }
                              );
                              

                              ergibt diese Fehlermeldungen:

                              javascript.0	20:17:23.191	info	Start JavaScript script.js.common.HycubeOliverIO (Javascript/js)
                              javascript.0	20:17:23.194	error	script.js.common.HycubeOliverIO: TypeError: Cannot read properties of null (reading 'headers')
                              javascript.0	20:17:23.195	error	at script.js.common.HycubeOliverIO:2:1
                              javascript.0	20:17:23.195	error	at script.js.common.HycubeOliverIO:25:3
                              

                              Vielleicht hilft dir das weiter...

                              OliverIO 2 Replies Last reply Reply Quote 0
                              • OliverIO
                                OliverIO @schnipsel71 last edited by

                                @schnipsel71 sagte in Zugangsgeschützte API-Schnittstelle auslesen mit Blockly:

                                http://ip/auth/

                                wir nähern uns httpGet hat 2 Argumente und httpPost hat 3

                                httpGet(
                                    'http://ip/auth/',
                                    {
                                        basicAuth: {
                                            user: 'hycube',
                                            password: 'hycube'
                                        }
                                    },
                                    (error, response) => {
                                        if (!error) {
                                            console.log(response.statusCode);
                                            console.log(response.data);
                                            console.log(response.headers);
                                        } else {
                                            console.error(error);
                                        }
                                    }
                                );
                                

                                bitte über den werkzeugschlüssel auch mal noch alles anschalten
                                bfa52630-e698-48d6-b5e9-6e092680d7dd-image.png

                                S T 2 Replies Last reply Reply Quote 0
                                • S
                                  schnipsel71 @OliverIO last edited by

                                  @oliverio Okay, folgende Meldungen:

                                  javascript.0	20:47:50.692	info	Start JavaScript script.js.common.HycubeOliverIO (Javascript/js)
                                  javascript.0	20:47:50.702	info	script.js.common.HycubeOliverIO: httpGet(config={"method":"get","url":"http://ip/auth/","responseType":"text","responseEncoding":"utf8","timeout":2000,"auth":{"username":"hycube","password":"hycube"},"headers":{"User-Agent":"Mozilla/5.0 (X11; Linux i686; rv:109.0) Gecko/20100101 Firefox/121.0"}})
                                  javascript.0	20:47:50.703	info	script.js.common.HycubeOliverIO: registered 0 subscriptions, 0 schedules, 0 messages, 0 logs and 0 file subscriptions
                                  javascript.0	20:47:50.741	info	script.js.common.HycubeOliverIO: 401
                                  javascript.0	20:47:50.741	info	script.js.common.HycubeOliverIO:
                                  javascript.0	20:47:50.741	info	script.js.common.HycubeOliverIO: Object [AxiosHeaders] { 'access-control-allow-headers': 'Authorization', 'access-control-allow-origin': '*', connection: 'close', 'content-length': '0', 'content-type': 'cty', 'www-authenticate': 'Basic realm="00"' }
                                  

                                  Leider ist die böse 401 wieder dabei...

                                  1 Reply Last reply Reply Quote 0
                                  • T
                                    TT-Tom @OliverIO last edited by

                                    @oliverio

                                    Hatte ich schon mal gefragt, dein Code. Hatte irgendwie nicht funktioniert.

                                    Ps: jetzt ist erstmal EM kucken 😁

                                    1 Reply Last reply Reply Quote 0
                                    • OliverIO
                                      OliverIO @schnipsel71 last edited by

                                      @schnipsel71

                                      nein der ist falsch, wie gesagt, bei get nur 2 argumente (url+config)
                                      und bei httppost 3 argumente, url+daten+config

                                      OliverIO 1 Reply Last reply Reply Quote 0
                                      • OliverIO
                                        OliverIO @OliverIO last edited by OliverIO

                                        @oliverio

                                        so jetzt per header.
                                        einmal so wie es sein sollte und einmal ein header wie er bei request wohl funktioniert hat, aber eigentlich nicht richtig ist. Das Basic wird angegeben fließt aber in die base64 kodierung nicht ein

                                        httpGet(
                                            'http://jsonplaceholder.typicode.com/posts',
                                            {
                                                headers: {
                                                    "Authorization": "Basic " + Buffer.from("hycube:hycube").toString("base64")
                                                }
                                            },
                                            (error, response) => {
                                                if (!error) {
                                                    console.log(response.statusCode);
                                                    console.log(response.data);
                                                    console.log(response.headers);
                                                } else {
                                                    console.error(error);
                                                }
                                            }
                                        );
                                        
                                        httpGet(
                                            'http://jsonplaceholder.typicode.com/posts',
                                            {
                                                headers: {
                                                    "Authorization": Buffer.from("Basic hycube:hycube").toString("base64")
                                                }
                                            },
                                            (error, response) => {
                                                if (!error) {
                                                    console.log(response.statusCode);
                                                    console.log(response.data);
                                                    console.log(response.headers);
                                                } else {
                                                    console.error(error);
                                                }
                                            }
                                        );
                                        
                                        S 1 Reply Last reply Reply Quote 0
                                        • S
                                          schnipsel71 @OliverIO last edited by schnipsel71

                                          @oliverio Ich verstehe nicht ganz: Was hat der Code mit meiner Anlage von Hycube zu tun? Ist die URL ein Versehen und soll dort stattdessen die IP meiner Hycube-Anlage stehen?
                                          Wenn ich folgenden Code teste:

                                          httpGet(
                                              'http://ip/auth/',
                                              {
                                                  headers: {
                                                      "Authorization": Buffer.from("Basic hycube:hycube").toString("base64")
                                                  }
                                              },
                                              (error, response) => {
                                                  if (!error) {
                                                      console.log(response.statusCode);
                                                      console.log(response.data);
                                                      console.log(response.headers);
                                                  } else {
                                                      console.error(error);
                                                  }
                                              }
                                          );
                                          

                                          dann bekomme ich folgende LOG-Einträge:

                                          javascript.0	23:49:41.323	info	Start JavaScript script.js.common.HycubeOliverIO (Javascript/js)
                                          javascript.0	23:49:41.325	info	script.js.common.HycubeOliverIO: httpGet(config={"method":"get","url":"http://ip/auth/","responseType":"text","responseEncoding":"utf8","timeout":2000,"headers":{"User-Agent":"Mozilla/5.0 (X11; Linux i686; rv:109.0) Gecko/20100101 Firefox/121.0","Authorization":"QmFzaWMgaHljdWJlOmh5Y3ViZQ=="}})
                                          javascript.0	23:49:41.326	info	script.js.common.HycubeOliverIO: registered 0 subscriptions, 0 schedules, 0 messages, 0 logs and 0 file subscriptions
                                          javascript.0	23:49:41.392	info	script.js.common.HycubeOliverIO: 200
                                          javascript.0	23:49:41.392	info	script.js.common.HycubeOliverIO: ewogICAgIlBlcm1pc3Npb24iOiAzLAogICAgImV4cCI6IDE3MjA5OTczODEKfQo=
                                          javascript.0	23:49:41.392	info	script.js.common.HycubeOliverIO: Object [AxiosHeaders] { 'access-control-allow-headers': 'Authorization', 'access-control-allow-origin': '*', connection: 'close', 'content-length': '64', 'content-type': 'cty' }
                                          
                                          OliverIO 1 Reply Last reply Reply Quote 0
                                          • OliverIO
                                            OliverIO @schnipsel71 last edited by

                                            @schnipsel71

                                            ja mit der url habe ich getestet.
                                            das ergebnis sieht sehr gut aus.
                                            http 200 heiß erfolg

                                            und
                                            ewogICAgIlBlcm1pc3Npb24iOiAzLAogICAgImV4cCI6IDE3MjA5OTczODEKfQo

                                            ist der session token für die nächste abfrage.
                                            keine angst der ist sicherlich schon abgelaufen und das gerät ist ja nur in deinem lan erreichbar
                                            welche der beiden versionen war das jetzt?

                                            S 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            1.1k
                                            Online

                                            31.7k
                                            Users

                                            79.7k
                                            Topics

                                            1.3m
                                            Posts

                                            6
                                            77
                                            3531
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo