🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    req.status_code

    UIFlow
    2
    5
    6.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      Wolli01
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • ZontexZ
        Zontex
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • W
          Wolli01
          last edited by

          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!

          ZontexZ 1 Reply Last reply Reply Quote 0
          • ZontexZ
            Zontex @Wolli01
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • W
              Wolli01
              last edited by Wolli01

              '''

              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---------------------------------------
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post