req.status_code



  • req = urequests.request(method='GET', url='http://xxx.de/Datum.txt')
    print(str(req.status_code))

    The status code is displayed on the first pass, but not on the second pass. What could be the reason for this?



  • Hello, what pass are you referring to? could you please provide the complete code including what Core module are you trying to run it on and the result you are getting? please use the ``` quotes when you write code such as:

    req = urequests.request(method='GET', url='http://xxx.de/Datum.txt')
    print(str(req.status_code))
    

    Thanks



  • Module is Core2.
    It runs in a loop While True:
    On the first run, everything runs correctly.
    From the second run on, the status code is no longer displayed. It is simply skipped!



  • @wolli01 can you please attach a complete code or if it's UIFlow could you attach a screenshot of your blocks? the python code will also help.



  • '''

    Update der Settingdaten holen---------------------------------------

        if (Verbindung) == 1 and wifiCfg.wlan_sta.isconnected(): #Nur bei bestehender Internet Verbindung
            print("-----------------------------------------------")
            print("Überprüfe ob es eine Online-Setting Datei gibt")
            try:
    
                try:
                  req = urequests.request(method='GET', url=settings.Gateway+'onlinesettings.txt')
                  print('onlinesettings.txt wurde auf vorhandensein überprüft')
                  print(str(req.status_code))
                  time.sleep(1)
                except:
                  print('onlinesettings.txt ist nicht vorhanden')
    
                if (req.status_code == 200) :
                    print('onlinesettings Uebertragung OK')
    
                    if (ssd1306) == 1:
                        if (settings.Display) == 1:
                            lcd.print("Online Update, Setting erfolgt...",0,170,0xb8b8b8)               
                    time.sleep(1) #Warte 1 Sekunden
    
                    with open('/sd/settings.py', 'w') as updatefile:
                        updatefile.write(req.text)
                    updatefile.close()
                    print('onlinesettings wurde neu erstellt')
                    time.sleep(1)
                    
                    #Datei wieder löschen-------------
                    req = urequests.request(method='GET', url=settings.Gateway+'killsettings.php')
                    print('Setting Datei wurde auf dem Server wieder geloescht')
                    time.sleep(1)
                    Setting_Online_Update = 1
                    
                else:
                    print('Keine Setting Datei vorhanden!')
                    print("-------------------------------------------")                    
                    
    
            except Exception as e:
                print('Fehler!')
                print(e)
    

    Update der Settingdaten holen---------------------------------------

        # On Off Einstellungen holen---------------------------------------
        if (Verbindung) == 1 and wifiCfg.wlan_sta.isconnected(): #Nur bei bestehender Internet Verbindung
            print("Überprüfe ob übers Internet ausgeschaltet wird")
            try:
    
                try:
                  req1 = urequests.request(method='GET', url=settings.Gateway+'onoff.txt')
                  print('onoff.txt wurde auf vorhandensein überprüft')
                  print(str(req1.status_code))
                  time.sleep(1)
                except:
                  print('onoff.txt ist nicht vorhanden')
    
                  if (req1.status_code == 200) :
                       print('onoff Uebertragung OK')
                       OnOff = 0 # An Aus Schalter = Aus
                        
                      #Datei wieder löschen-------------
                       req2 = urequests.request(method='GET', url=settings.Gateway+'killpoweronoff.php')
                       print('On-Off Datei wurde auf dem Server wieder geloescht')
                       time.sleep(1)
                        
                  else:
                       print('Keine On-Off Datei vorhanden!')
                       print("-------------------------------------------")                        
    
            except Exception as e:
                print('Fehler!')
                print(e)
        # On Off Einstellungen holen---------------------------------------