Ankündigung

Einklappen
Keine Ankündigung bisher.

HTTP Request

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    HTTP Request

    Hat jemand eine Idee, wie dies hier zustande kommt:

    Code:
    2017-06-06  12:47:29 INFO     hello        Hello World!
    2017-06-06  12:50:34 ERROR    Pool2        Logic: Pool2, File: /usr/local/lib/python3.5/http/client.py, Line: 266, Method: _read_status, Exception: Remote end closed connection without response
    Traceback (most recent call last):
      File "/usr/local/smarthome/lib/scheduler.py", line 378, in _task
        exec(obj.bytecode)
      File "/usr/local/smarthome/logics/OSF2.py", line 3, in <module>
        req = urllib.request.urlopen("http://PC40-1/stathei.htm")
      File "/usr/local/lib/python3.5/urllib/request.py", line 163, in urlopen
        return opener.open(url, data, timeout)
      File "/usr/local/lib/python3.5/urllib/request.py", line 466, in open
        response = self._open(req, data)
      File "/usr/local/lib/python3.5/urllib/request.py", line 484, in _open
        '_open', req)
      File "/usr/local/lib/python3.5/urllib/request.py", line 444, in _call_chain
        result = func(*args)
      File "/usr/local/lib/python3.5/urllib/request.py", line 1282, in http_open
        return self.do_open(http.client.HTTPConnection, req)
      File "/usr/local/lib/python3.5/urllib/request.py", line 1257, in do_open
        r = h.getresponse()
      File "/usr/local/lib/python3.5/http/client.py", line 1197, in getresponse
        response.begin()
      File "/usr/local/lib/python3.5/http/client.py", line 297, in begin
        version, status, reason = self._read_status()
      File "/usr/local/lib/python3.5/http/client.py", line 266, in _read_status
        raise RemoteDisconnected("Remote end closed connection without"
    http.client.RemoteDisconnected: Remote end closed connection without response
    2017-06-06  12:50:45 INFO     CP Server Thread-8 192.168.178.21 - - [06/Jun/2017:12:50:45] "GET / HTTP/1.1" 401 1502 "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"
    2017-06-06  12:52:09 INFO     CP Server Thread-9 192.168.178.21 - - [06/Jun/2017:12:52:09] "GET / HTTP/1.1" 401 1502 "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0)
    das läuft einwandfrei unter smarthome.py ( mit Python 2.7 ). aber bringt diese Fehler mit SmartHomeNG
    ich schätze aber, das ist ein Python 3.5 Problem
    ich greife einfach via HTTP auf einen Server zu und hole dort Daten ab:

    Code:
    # OSF2
    import urllib.request
    req = urllib.request.urlopen("http://PC40-1/stathei.htm")
    data = req.read().decode('UTF-8')
    sh.Pool.Status.Heizung(data)
    words = data.split()
    if words[-1] == 'an':
     sh.Pool.Status.Solar("true")
    else:
     sh.Pool.Status.Solar("false")     
    #

    #2
    Meines Wissens hätte schon das alte SH.py nicht mit Python 2.x betrieben werden dürfen?!

    Kommentar


      #3
      Vielleicht solltest Du Deinen Code mal mit try ... except kapseln um dem Problem des Verbindungsabbruches einzugrenzen? Siehe dazu z.B. hier

      Kommentar


        #4
        danke für den Tipp bmx,

        war ein Schwergeburt den code einzufügen; habe es aber geschafft:

        Code:
        # OSF2
        from urllib.request import Request, urlopen
        from urllib.error import URLError, HTTPError
        #
        req = Request("http://PC40-1/stathei.htm")
        try:
         response = urlopen(req)
        except HTTPError as e:
         # do something
         logger.info('Error code: ', e.code)
        except URLError as e:
         # do something
         logger.info('Reason: ', e.reason)
        else:
         # do something
         logger.info('good!')
        #
        data = urlopen("http://PC40-1/stathei.htm").read().decode('UTF-8')
        sh.Pool.Status.Heizung(data)
        words = data.split()
        ..
        einmal geht's offensichtlich gut, danach kommt wieder der Fehler:
        diesmal aber beim try:

        Code:
        2017-06-07  12:08:54 INFO     BackendServer [07/Jun/2017:12:08:54] ENGINE Serving on http://192.168.178.41:8383
        2017-06-07  12:08:59 INFO     hello        Hello World!
        [B]2017-06-07  12:08:59 INFO     Pool2        good![/B]
        2017-06-07  12:09:09 INFO     Beschattung  Sonnenstand Winkel 141.0
        2017-06-07  12:09:09 INFO     Beschattung  Sonnenstand Neigung 57.0
        2017-06-07  12:09:09 INFO     Beschattung  Status Eltern: 0
        2017-06-07  12:09:09 INFO     Beschattung  Status Gäste : 0
        [B]2017-06-07  12:12:05 ERROR    Pool2        Logic: Pool2[/B], File: /usr/local/lib/python3.5/http/client.py, Line: 266, Method: _read_status, Exception: Remote end closed connection without response
        Traceback (most recent call last):
          File "/usr/local/smarthome/lib/scheduler.py", line 378, in _task
            exec(obj.bytecode)
          File "/usr/local/smarthome/logics/OSF2.py", line 7, in <module>
            response = urlopen(req)
          File "/usr/local/lib/python3.5/urllib/request.py", line 163, in urlopen
            return opener.open(url, data, timeout)
          File "/usr/local/lib/python3.5/urllib/request.py", line 466, in open
            response = self._open(req, data)
          File "/usr/local/lib/python3.5/urllib/request.py", line 484, in _open
            '_open', req)
          File "/usr/local/lib/python3.5/urllib/request.py", line 444, in _call_chain
            result = func(*args)
          File "/usr/local/lib/python3.5/urllib/request.py", line 1282, in http_open
            return self.do_open(http.client.HTTPConnection, req)
          File "/usr/local/lib/python3.5/urllib/request.py", line 1257, in do_open
            r = h.getresponse()
          File "/usr/local/lib/python3.5/http/client.py", line 1197, in getresponse
            response.begin()
          File "/usr/local/lib/python3.5/http/client.py", line 297, in begin
            version, status, reason = self._read_status()
          File "/usr/local/lib/python3.5/http/client.py", line 266, in _read_status
            raise RemoteDisconnected("Remote end closed connection without"
        http.client.RemoteDisconnected: Remote end closed connection without response
        2017-06-07  12:12:13 INFO     Main         VISU: Websocket handler uses protocol version 4

        Kommentar


          #5
          danach scheint es aber wieder gut zu gehen:
          Code:
          2017-06-07  13:00:01 INFO     Pool2        good!
          2017-06-07  13:03:01 INFO     Pool2        good!
          2017-06-07  13:06:01 INFO     Pool2        good!
          2017-06-07  13:09:01 INFO     Pool2        good!
          2017-06-07  13:12:01 INFO     Pool2        good!
          2017-06-07  13:15:01 INFO     Pool2        good!
          2017-06-07  13:18:01 INFO     Pool2        good!
          2017-06-07  13:21:01 INFO     Pool2        good!
          2017-06-07  13:24:01 INFO     Pool2        good!

          Kommentar


            #6
            Ich hätte es vermutlich ein wenig anders geschrieben. Probier mal folgendes und versuche den Code zu verstehen:
            Code:
            # OSF2
            import urllib
            import logging
            myurl = "http://PC40-1/stathei.htm"
            
            logger = logging.getLogger('logics.'+__name__)
            
            try:
                req = urllib.request.urlopen(myurl)
                data = req.read().decode('UTF-8')
            except HTTPError as e:    
                logger.error('HTTP Fehler mit error code: ', e.code)
            except URLError as e:
                logger.error('URL Fehler {} bei Adresse {} aufgetreten'.format(e.code, myurl))
            except RemoteDisconnected as e:
                logger.error('Verbindung ohne Rückmeldung geschlossen {]'.format(e.code))
            else:
                sh.Pool.Status.Heizung(data)
                words = data.split()
                if words[-1] == 'an':
                    sh.Pool.Status.Solar("true")
                else:
                    sh.Pool.Status.Solar("false")
            PS: Getestet habe ich den Code jetzt noch nicht...


            Kommentar


              #7
              Oder einfach die Requests lib dafür nehmen? :>

              Kommentar


                #8
                Ja, oder so...

                Kommentar


                  #9
                  das ganze OO Geraffel ist schon schwer zu verstehen.
                  habe Deinen Code wie folgt übernommen/angepasst:

                  Code:
                  # OSF2
                  import http
                  import urllib
                  import logging
                  logger = logging.getLogger('logics.'+__name__)
                  
                  myurl = "http://PC40-1/stathei.htm"
                  
                  try:
                   req = urllib.request.urlopen(myurl)
                   data = req.read().decode('UTF-8')
                  except urllib.error.HTTPError as e:   
                   logger.error('HTTP Fehler mit error code: ', e.code)
                  except urllib.error.URLError as e:
                   logger.error('URL Fehler {} bei Adresse {} aufgetreten'.format(e.code, myurl))
                  except http.client.RemoteDisconnected as e:
                   logger.error('Verbindung ohne Rückmeldung geschlossen {]'.format(e.code))
                  else:
                   sh.Pool.Status.Heizung(data)
                   words = data.split()
                   if words[1] == 'Solarheizung':
                    sh.Pool.Status.Solar("true")
                   else:
                    sh.Pool.Status.Solar("false")     
                   if words[1] == 'Wärmetauscher-Heizung':
                    sh.Pool.Status.WP("true")
                   else:
                    sh.Pool.Status.WP("false")     
                   #logger.info(data)
                  #
                  jetzt scheitere ich noch an diesem Fehler:

                  Code:
                  2017-06-07  18:01:19 ERROR    Pool2        Logic: Pool2, File: /usr/local/smarthome/logics/OSF2.py, Line: 21, Method: <module>, Exception: 'RemoteDisconnected' object has no attribute 'code'
                  Traceback (most recent call last):
                    File "/usr/local/smarthome/logics/OSF2.py", line 14, in <module>
                      req = urllib.request.urlopen(myurl)
                    File "/usr/local/lib/python3.5/urllib/request.py", line 163, in urlopen
                      return opener.open(url, data, timeout)
                    File "/usr/local/lib/python3.5/urllib/request.py", line 466, in open
                      response = self._open(req, data)
                    File "/usr/local/lib/python3.5/urllib/request.py", line 484, in _open
                      '_open', req)
                    File "/usr/local/lib/python3.5/urllib/request.py", line 444, in _call_chain
                      result = func(*args)
                    File "/usr/local/lib/python3.5/urllib/request.py", line 1282, in http_open
                      return self.do_open(http.client.HTTPConnection, req)
                    File "/usr/local/lib/python3.5/urllib/request.py", line 1257, in do_open
                      r = h.getresponse()
                    File "/usr/local/lib/python3.5/http/client.py", line 1197, in getresponse
                      response.begin()
                    File "/usr/local/lib/python3.5/http/client.py", line 297, in begin
                      version, status, reason = self._read_status()
                    File "/usr/local/lib/python3.5/http/client.py", line 266, in _read_status
                      raise RemoteDisconnected("Remote end closed connection without"
                  http.client.RemoteDisconnected: Remote end closed connection without response
                  
                  During handling of the above exception, another exception occurred:
                  
                  Traceback (most recent call last):
                    File "/usr/local/smarthome/lib/scheduler.py", line 378, in _task
                      exec(obj.bytecode)
                    File "/usr/local/smarthome/logics/OSF2.py", line 21, in <module>
                      logger.error('Verbindung ohne Rückmeldung geschlossen {]'.format(e.code))
                  AttributeError: 'RemoteDisconnected' object has no attribute 'code'
                  sorry, das geht für mich eine Nummer zu weit; ich kann kein Python.
                  aber unter smarthome.py hat meine einfache Lösung (ohne try einwandfrei funktioniert.

                  Kommentar


                    #10

                    Änder mal logger.error('Verbindung ohne Rückmeldung geschlossen {]'.format(e.code)) in
                    logger.error('Verbindung ohne Rückmeldung geschlossen {]'.format(e))

                    Kommentar


                      #11
                      schaut mal bitte hier unter http.client:
                      http://python.readthedocs.io/en/late...tsnew/3.5.html
                      da ist die Anpassung in Python3.5 die zu diesem Fehler führt beschrieben.

                      Kommentar


                        #12
                        Ja, das ist schon klar. Es tritt halt die Ausnahme "RemoteDisconnected" auf. Die wird mit dem obigen Code auch nur abgefangen und nicht die Ursachen beseitigt.
                        Es ist nur dann so, das Du

                        a) im Log eben nicht diese riesige Fehlermeldung bekommst und
                        b) wenn der Code nicht funktioniert, ist das Ergebnis ungültig und damit sollte auch Dein Code zur Auswertung eben nicht ausgeführt werden.

                        Kommentar


                          #13
                          Es hat eigentlich ein paar Jahre so funktioniert.
                          jetzt nach der Umstellung auf SHNG 1.9 taucht das Problem wieder auf, aber in einer etwas anderen Form.
                          Ich nutze mittlerweile auch das PyPi requests package.

                          im log wirkt sich das jetzt so aus:
                          Code:
                          2022-04-27 15:46:13 ERROR logics.Pool2 In der Logik ist ein Fehler aufgetreten:
                          Logik 'Pool2', Datei '/home/smarthome/.local/lib/python3.7/site-packages/requests/adapters.py', Zeile 501
                          function send(), Exception: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
                          auch mit einer stark vereinfachten Logik tritt der Fehler sporadisch auf
                          Code:
                          # OSF2
                          import requests
                          
                          req = requests.get("http://192.168.178.40/statpum.htm")
                          data = req.text
                          sh.Pool.Status.Pumpe.Stufe(data)
                          time.sleep(5)
                          req = requests.get("http://192.168.178.40/tempa.htm")
                          data = req.text
                          sh.Pool.Istwerte.Luft(data)
                          das geht dann so weit, dass sich im scheduler die threads alle aufhängen und SHNG dann bei einem limit neu started.

                          hat jemand ein Idee, wo die Fehlermeldung herkommt und wie ich Abhilfe schaffen könnte ?
                          SHNG benutzt bei mir requests version: 2.27.1 ( scheint die neueste zu sein )

                          Kommentar


                            #14
                            mal ein kompletter log Mitschnitt von heute Morgen.
                            hat alles irgendwie mit HTTP und/oder Netzwerk zu tun
                            Code:
                            2022-04-28  10:47:12 ERROR    logics.Pool2        In der Logik ist ein Fehler aufgetreten:
                               Logik 'Pool2', Datei '/home/smarthome/.local/lib/python3.7/site-packages/requests/adapters.py', Zeile 501
                               function send(), Exception: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
                            2022-04-28  11:27:07 ERROR    plugins.avm         fritzbox_7490@: Exception when sending POST request for updating item towards the FritzDevice: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
                            2022-04-28  11:27:07 ERROR    plugins.avm         fritzbox_7490@: _get_aha_device_elements: error syntax error: line 1, column 0 during parsing
                            2022-04-28  12:32:37 ERROR    logics.Pool2        In der Logik ist ein Fehler aufgetreten:
                               Logik 'Pool2', Datei '/home/smarthome/.local/lib/python3.7/site-packages/requests/adapters.py', Zeile 501
                               function send(), Exception: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
                            2022-04-28  12:33:55 ERROR    modules.admin.api_plugins _test_for_blog_articles: OSError ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
                            2022-04-28  12:51:22 ERROR    plugins.hue2        poll_bridge_lights: Exception HTTPConnectionPool(host='192.168.178.50', port=80): Max retries exceeded with url: /api/xxxxxxxxxxxxx/lights (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xa3bd0e90>, 'Connection to 192.168.178.50 timed out. (connect timeout=5)'))
                            2022-04-28  13:02:13 ERROR    logics.Pool2        In der Logik ist ein Fehler aufgetreten:
                               Logik 'Pool2', Datei '/home/smarthome/.local/lib/python3.7/site-packages/requests/adapters.py', Zeile 501
                               function send(), Exception: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
                            Zuletzt geändert von whe; 28.04.2022, 12:15.

                            Kommentar

                            Lädt...
                            X