Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gel.] Script: Adresse ermitteln -> axios ändern in httpget

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gel.] Script: Adresse ermitteln -> axios ändern in httpget

    This topic has been deleted. Only users with topic management privileges can see it.
    • Homoran
      Homoran Global Moderator Administrators @bahnuhr last edited by

      @bahnuhr sagte in Script: Adresse ermitteln -> axios ändern in httpget:

      You have been blocked because you have violated the "https://operations.osmfoundation.org/policies/nominatim/

      ich fürchte du hast es zu oft versucht

      1 Reply Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators @bahnuhr last edited by

        @bahnuhr sagte in Script: Adresse ermitteln -> axios ändern in httpget:

        make sure that your 'software adheres to the terms. You should in particular verify that you have set a custom HTTP referrer or HTTP user agent that identifies your application, and 'that you are not overusing the service with massive bulk requests

        1 Reply Last reply Reply Quote 0
        • F
          fastfoot @bahnuhr last edited by

          @bahnuhr warum überhaupt umstellen? httpGet nutzt unter der Haube eh axios, löscht aber den default user-agent den axios ohne Angabe desselben wohl setzt. Anyway:

          var latitude = 48.46567;
          var longitude = 9.7107;
          
          updateLocation(latitude, longitude);
          
          async function updateLocation(latitude, longitude) {
              const url = `https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=json`;
              const response = await httpGetAsync(url, { headers: { "user-agent": 'ioBroker script' } });
              const data = JSON.parse(response.data);
              if (response && data) {
                  log(data)
                  log(data.display_name);
                  return (data.display_name);
              }
          }
          
          
          haus-automatisierung 1 Reply Last reply Reply Quote 0
          • haus-automatisierung
            haus-automatisierung Developer Most Active @fastfoot last edited by

            @fastfoot Ich meine hier gab es irgendwo mal Scripts, welche bei jeder Anfrage einen anderen User-Agent generiert haben (um zu verhindern, dass OpenStreeMap einen aussperrt?). Scheint ja ein recht spezielles Thema zu sein.

            Ro75 DJMarc75 F 3 Replies Last reply Reply Quote 1
            • Ro75
              Ro75 @haus-automatisierung last edited by

              @haus-automatisierung

              das ist meine Lösung für einen Random-USER-Agent

              function UAChrome() {
                  const Plattform = Math.floor(Math.random() * 2)
                  const chromeVersion = Math.floor(Math.random() * 20) + 60;
                  const webkitVersion = Math.floor(Math.random() * 700) + 500;
                  const osPlatform = Plattform == 1 ? 'Win64; x64' : 'Macintosh; Intel Mac OS X 10_15_0';
                  const userAgent = `Mozilla/5.0 (${osPlatform}) AppleWebKit/${webkitVersion}.36 (KHTML, like Gecko) Chrome/${chromeVersion}.0.3163.100 Safari/${webkitVersion}.36`;
                  return userAgent;
              }
              
              function UAFirefox() {
                  const Plattform = Math.floor(Math.random() * 2)
                  const firefoxVersion = Math.floor(Math.random() * 5) + 55;
                  const geckoVersion = Math.floor(Math.random() * 30) + 20100101;
                  const osPlatform = Plattform == 1 ? 'Win64; x64' : 'Macintosh; Intel Mac OS X 10_15_0';
                  const userAgent = `Mozilla/5.0 (${osPlatform}; rv: ${firefoxVersion}.0) Gecko/${geckoVersion} Firefox/${firefoxVersion}.0`;
                  return userAgent;
              }
              
              function UASafari() {
                  const Plattform = Math.floor(Math.random() * 2)
                  const safariVersion = Math.floor(Math.random() * 5) + 10;
                  const osPlatform = Plattform == 1 ? 'Win64; x64' : 'Macintosh; Intel Mac OS X 10_15_0';
                  const userAgent = `Mozilla/5.0 (${osPlatform}) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/${safariVersion}.1.15 Safari/605.1.15`;
                  return userAgent;
                }
              
              function UAAndroid() {
                  const androidVersion = Math.floor(Math.random() * 5) + 5;
                  const chromeVersion = Math.floor(Math.random() * 20) + 60;
                  const webkitVersion = Math.floor(Math.random() * 700) + 500;
                  const osPlatform = `Linux; Android ${androidVersion}.${Math.floor(Math.random() * 10)}; en-us; Nexus 6 Build/LYZ28M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion}.0.3163.98 Mobile Safari/${webkitVersion}.36`;
                  const userAgent = `Mozilla/5.0 (${osPlatform}`;
                  return userAgent;
              }
              
              function UAIos() {
                  const iosVersion = Math.floor(Math.random() * 5) + 9;
                  const safariVersion = Math.floor(Math.random() * 5) + 600;
                  const webkitVersion = Math.floor(Math.random() * 700) + 500;
                  const osPlatform = `CPU iPhone OS ${iosVersion}_${Math.floor(Math.random() * 10)} like Mac OS X) AppleWebKit/${webkitVersion}.60 (KHTML, like Gecko) Version/${safariVersion}.0 Mobile/15E148 Safari/${webkitVersion}.60`;
                  const userAgent = `Mozilla/5.0 (${osPlatform}`;
                  return userAgent;
              }
              
              function RUA() {
                  const UA = Math.floor(Math.random() * 4)
                  var UserAgent = '';
              
                  if (UA == 0) {
                      UserAgent = UAChrome();
                  } else if (UA == 1) {
                      UserAgent = UAFirefox();
                  } else if (UA == 2) {
                      UserAgent = UASafari();
                  } else if (UA == 3) {
                      UserAgent = UAAndroid();
                  } else if (UA == 4) {
                      UserAgent = UAIos();
                  }
                  return UserAgent;
              }
              
              console.log(RUA());
              

              @homoran sagte in Script: Adresse ermitteln -> axios ändern in httpget:

              You have been blocked because you have violated the "https://operations.osmfoundation.org/policies/nominatim/

              Maximal pro Tag 2500 Aufrufe.

              Ro75.

              1 Reply Last reply Reply Quote 3
              • DJMarc75
                DJMarc75 @haus-automatisierung last edited by

                @haus-automatisierung sagte in Script: Adresse ermitteln -> axios ändern in httpget:

                hier gab es irgendwo mal Scripts, welche bei jeder Anfrage einen anderen User-Agent generiert haben

                ja, irgendwo war da was - und daraus hab ich mir ein Blockly mit Funktion gebaut.

                Ich selbst kann kein JS aber ich stelle mal den generierten JS-Code aus meinem Blockly rein:

                var lon, lat, sDP, json, strasse, hausnummer, plz, stadt;
                
                // Beschreibe diese Funktion …
                async function osmResolve(lon, lat, sDP) {
                    function UAChrome() {
                        const Plattform = Math.floor(Math.random() * 2)
                        const chromeVersion = Math.floor(Math.random() * 20) + 60;
                        const webkitVersion = Math.floor(Math.random() * 700) + 500;
                        const osPlatform = Plattform == 1 ? 'Win64; x64' : 'Macintosh; Intel Mac OS X 10_15_0';
                        const userAgent = `Mozilla/5.0 (${osPlatform}) AppleWebKit/${webkitVersion}.36 (KHTML, like Gecko) Chrome/${chromeVersion}.0.3163.100 Safari/${webkitVersion}.36`;
                        return userAgent;
                    }
                
                    function UAFirefox() {
                        const Plattform = Math.floor(Math.random() * 2)
                        const firefoxVersion = Math.floor(Math.random() * 5) + 55;
                        const geckoVersion = Math.floor(Math.random() * 30) + 20100101;
                        const osPlatform = Plattform == 1 ? 'Win64; x64' : 'Macintosh; Intel Mac OS X 10_15_0';
                        const userAgent = `Mozilla/5.0 (${osPlatform}; rv: ${firefoxVersion}.0) Gecko/${geckoVersion} Firefox/${firefoxVersion}.0`;
                        return userAgent;
                    }
                
                    function UASafari() {
                        const Plattform = Math.floor(Math.random() * 2)
                        const safariVersion = Math.floor(Math.random() * 5) + 10;
                        const osPlatform = Plattform == 1 ? 'Win64; x64' : 'Macintosh; Intel Mac OS X 10_15_0';
                        const userAgent = `Mozilla/5.0 (${osPlatform}) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/${safariVersion}.1.15 Safari/605.1.15`;
                        return userAgent;
                      }
                
                    function UAAndroid() {
                        const androidVersion = Math.floor(Math.random() * 5) + 5;
                        const chromeVersion = Math.floor(Math.random() * 20) + 60;
                        const webkitVersion = Math.floor(Math.random() * 700) + 500;
                        const osPlatform = `Linux; Android ${androidVersion}.${Math.floor(Math.random() * 10)}; en-us; Nexus 6 Build/LYZ28M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion}.0.3163.98 Mobile Safari/${webkitVersion}.36`;
                        const userAgent = `Mozilla/5.0 (${osPlatform}`;
                        return userAgent;
                    }
                
                    function UAIos() {
                        const iosVersion = Math.floor(Math.random() * 5) + 9;
                        const safariVersion = Math.floor(Math.random() * 5) + 600;
                        const webkitVersion = Math.floor(Math.random() * 700) + 500;
                        const osPlatform = `CPU iPhone OS ${iosVersion}_${Math.floor(Math.random() * 10)} like Mac OS X) AppleWebKit/${webkitVersion}.60 (KHTML, like Gecko) Version/${safariVersion}.0 Mobile/15E148 Safari/${webkitVersion}.60`;
                        const userAgent = `Mozilla/5.0 (${osPlatform}`;
                        return userAgent;
                    }
                
                    function RUA() {
                        const UA = Math.floor(Math.random() * 4);
                
                        if (UA == 0) {
                            return UAChrome();
                        } else if (UA == 1) {
                            return UAFirefox();
                        } else if (UA == 2) {
                            return UASafari();
                        } else if (UA == 3) {
                            return UAAndroid();
                        } else if (UA == 4) {
                            return UAIos();
                        }
                
                        return '';
                    }
                
                    httpGet(
                        `https://nominatim.openstreetmap.org/reverse?format=geojson&lat=${lat}&lon=${lon}`,
                        {
                            timeout: 15000,
                            headers: {
                                'User-Agent': RUA(),
                            },
                        },
                        (err, response) => {
                            if (!err  && response.statusCode == 200) {
                                const info = JSON.parse(response.data);
                                const address = info.features[0].properties.address;
                
                                setState(sDP, JSON.stringify(address), true);
                            } else {
                                console.error(`Nominatim: ${response.statusCode}`);
                            }
                        }
                    );
                
                }
                
                
                on({ id: [].concat(['0_userdata.0.GPS.Marc.Adressabfrage']), change: 'ne' }, async (obj) => {
                  let value = obj.state.val;
                  let oldValue = obj.oldState.val;
                  await osmResolve(getState('0_userdata.0.GPS.Marc.lon').val, getState('0_userdata.0.GPS.Marc.lat').val, '0_userdata.0.GPS.Marc.AdresseJson');
                  json = getState('0_userdata.0.GPS.Marc.AdresseJson').val;
                  strasse = getAttr(json, 'road');
                  hausnummer = getAttr(json, 'house_number');
                  plz = getAttr(json, 'postcode');
                  stadt = getAttr(json, 'town');
                  setState('0_userdata.0.GPS.Marc.Adresse' /* Adresse */, ([strasse,' ',hausnummer,', ',plz,' ',stadt].join('')), true);
                });
                

                und während ich schreibe war @Ro75 schneller 😉

                1 Reply Last reply Reply Quote 1
                • F
                  fastfoot @haus-automatisierung last edited by

                  @haus-automatisierung also hier lag das Problem nur daran dass httpGet gar keinen user-agent mitsendet. Mit axios wurde er ja auch nie blockiert und das ändert den user-agent ja nicht. Ist halt alles schwierig für Nichtprogrammierer, aber immerhin gibt es ja das Forum...

                  haus-automatisierung 1 Reply Last reply Reply Quote 0
                  • haus-automatisierung
                    haus-automatisierung Developer Most Active @fastfoot last edited by

                    @fastfoot sagte in Script: Adresse ermitteln -> axios ändern in httpget:

                    also hier lag das Problem nur daran dass httpGet gar keinen user-agent mitsendet

                    Natürlich wird im Standard ein Agent gesendet. Siehst Du ja im verbose mode sofort.

                    F 1 Reply Last reply Reply Quote 0
                    • F
                      fastfoot @haus-automatisierung last edited by

                      @haus-automatisierung upps, meine Annahme beruhte darauf dass ich ohne Angabe eines UA sofort gesperrt wurde, nach dem Setzen eines beliebigen UA (siehe codeschnipsel) ich aber sofort eine Antwort bekam. Tja, wieder was gelernt, man(ich!) sollte aus Schlussfolgerungen keine Tatsachen ableiten. Sorry for that! Dann bleibt nur die Vermutung dass der Inhalt des UA geprüft wird

                      haus-automatisierung bahnuhr 2 Replies Last reply Reply Quote 1
                      • haus-automatisierung
                        haus-automatisierung Developer Most Active @fastfoot last edited by

                        @fastfoot Alles gur. Ich wäre schon zufrieden, wenn viele Aussagen im Forum bei Unsicherheit als Frage formuliert würden 😉

                        1 Reply Last reply Reply Quote 1
                        • bahnuhr
                          bahnuhr Forum Testing Most Active @fastfoot last edited by

                          @fastfoot sagte in Script: Adresse ermitteln -> axios ändern in httpget:

                          dass ich ohne Angabe eines UA sofort gesperrt wurde

                          war bei mir auch so. Und 2500 Abfragen hab ich nie erreicht.
                          Ablehnung kam sofort.

                          @DJMarc75
                          @fastfoot
                          @haus-automatisierung
                          @Homoran
                          @Ro75

                          Danke an alle für die Antworten. Damit kann ich was anfangen.

                          mfg
                          Dieter

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

                            @bahnuhr

                            Zum Testen, welche headers und sonstige Daten dein request so alles übermittelt, kannst du dir hier eine individuelle Server Adresse generieren lassen. Auf der Seite dann, siehst du dann die requests mit all seinen Daten Und headers
                            https://webhook.site/

                            Wenn du dann beide Informationen hast, kann man vergleichen, wo die Unterschiede liegen und ob man die eventuell über die Parameter von HTTPget beeinflussen kann.

                            bahnuhr 1 Reply Last reply Reply Quote 0
                            • bahnuhr
                              bahnuhr Forum Testing Most Active @OliverIO last edited by

                              @oliverio sagte in Script: Adresse ermitteln -> axios ändern in httpget:

                              Zum Testen, welche headers und sonstige Daten dein request so alles übermittelt, kannst du dir hier eine individuelle Server Adresse generieren lassen. Auf der Seite dann, siehst du dann die requests mit all seinen Daten Und headers

                              starker Text.
                              Hab ich so auf Anhieb nicht verstanden.

                              Komm ich aber noch dahinter 😉

                              Danke dir.

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

                                @bahnuhr

                                Axios oder httpget sendet Daten.
                                Irgendwo wohl auch unterschiedlich, obwohl hinter httpget auch axios steht.
                                Genau anhand diesem Unterschied wird der request aber abgelehnt.
                                Das es der User Agent String ist ist nur eine Vermutung. Serverbetreiber geben meistens nicht bekannt anhand welchen Kriterien sie ablehnen.

                                Mit diesem Test findest du hoffentlich dann den Unterschied auch wirklich raus, weil du siehst, was am anderen Ende ankommt und nicht nur was du weg sendest.

                                Ro75 F 2 Replies Last reply Reply Quote 1
                                • bahnuhr
                                  bahnuhr Forum Testing Most Active last edited by

                                  So, habe mal als Muster das von @DJMarc75 genommen.
                                  Also ohne dieses async und await; aber mit random

                                  sieht so aus:

                                  var lat = 48.46567; var lon = 9.7107;
                                  var v_random = String(Math.floor(Math.random() * 100)); log (v_random);
                                  
                                      httpGet(`https://nominatim.openstreetmap.org/reverse?format=geojson&lat=${lat}&lon=${lon}`,
                                          { timeout: 15000, headers: { 'User-Agent': "iob" + v_random, }, },
                                          (err, response) => {
                                              if (!err  && response.statusCode == 200) { const info = JSON.parse(response.data); const address = info.features[0].properties.address;
                                                  log ("Str= " + address.road); log ("Nr= " + address.house_number); 
                                                  log ("Plz= " + address.postcode); log ("Ort= " + address.municipality);
                                              } else { console.error(`Nominatim: ${response.statusCode}`); }
                                          }
                                      );
                                  
                                  1 Reply Last reply Reply Quote 1
                                  • Ro75
                                    Ro75 @OliverIO last edited by Ro75

                                    @oliverio sagte in Script: Adresse ermitteln -> axios ändern in httpget:

                                    Das es der User Agent String ist ist nur eine Vermutung. Serverbetreiber geben meistens nicht bekannt anhand welchen Kriterien sie ablehnen.

                                    Da bin ich für mich weiter. Für mich steht es fest, dass der USER-Agent zu 95% daran beteiligt ist. Ich hatte, als ich gesperrt wurde mein Abfrage-URL in meinen Windows-Browser eingegeben und da ging es. Im iobroker wiederholt mit dem Ergebnis = NO.

                                    Also mal die IP gewechselt. Ein Teil war anders, aber selbiges Ergebnis 1xJa und 1xNein. Nochmal die IP gewechselt. Komplett anderer Bereich, aber auch hier war das Ergebnis identisch.

                                    Für mich steht also fest, die prüfen IP ind Verbindung mit USER-Agent und Anzahl Aufrufe.

                                    Ich wechsel aller 6 Stunden den USER-Agent für Nominatim.

                                    httpGet('https://nominatim.openstreetmap.org/reverse?format=geojson&lat='+lat+'&lon='+lon, { timeout: 15000,"headers":{"User-Agent":"'" + RUA() + "'"}}, (error, response) => {
                                    
                                    

                                    Ro75.

                                    1 Reply Last reply Reply Quote 2
                                    • F
                                      fastfoot @OliverIO last edited by

                                      @oliverio also der einzige Unterschied auf der Seite ist der UA. axios sendet da als default nur axios/1.7.7 während httpGet da einen UA sendet der für mich wie der eines Browsers aussieht. Ich sehe keinen Grund den UA zu wechseln wie es einige hier tun, das ist nur der Versuch Restriktionen zu umgehen und schadet somit letztlich der Community

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

                                        @fastfoot

                                        Das Script bei dem axios verwendet wird und funktioniert, wird kein ua gesetzt. Siehe gleich erster Post.

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

                                          @oliverio axios setzt den selbst! Quasi als default

                                          OliverIO 1 Reply Last reply Reply Quote 0
                                          • bahnuhr
                                            bahnuhr Forum Testing Most Active @fastfoot last edited by

                                            @fastfoot sagte in Script: Adresse ermitteln -> axios ändern in httpget:

                                            Ich sehe keinen Grund den UA zu wechseln wie es einige hier tun,

                                            Naja; als normaler user bekommt man aber immer wieder gesagt:
                                            man soll httpget nehmen.
                                            request und axios sind alt.

                                            Dass bei httpget axios im Hintergrund ist, war mir bis jetzt neu.
                                            Und ein Wechsel des UA bei httpget scheint notwendig zu sein, denn ohne dies klappt es offensichtlich nicht.

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            908
                                            Online

                                            31.9k
                                            Users

                                            80.1k
                                            Topics

                                            1.3m
                                            Posts

                                            7
                                            33
                                            1281
                                            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