Kaynağa Gözat

properly differentiate between timeout (printer not reachable) and api error

Thomas Buck 3 yıl önce
ebeveyn
işleme
df1fe1cece
1 değiştirilmiş dosya ile 9 ekleme ve 7 silme
  1. 9
    7
      src/octotray.py

+ 9
- 7
src/octotray.py Dosyayı Görüntüle

@@ -461,15 +461,17 @@ class OctoTray():
461 461
         else:
462 462
             data = content.encode('ascii')
463 463
             request = urllib.request.Request(url, data, headers)
464
+
464 465
         try:
465 466
             with urllib.request.urlopen(request, None, self.networkTimeout) as response:
466 467
                 text = response.read()
467 468
                 return text
468
-        except urllib.error.URLError:
469
-            pass
470
-        except urllib.error.HTTPError:
471
-            pass
472
-        return "error"
469
+        except (urllib.error.URLError, urllib.error.HTTPError) as error:
470
+            print("Error requesting URL \"" + url + "\": \"" + str(error) + "\"")
471
+            return "error"
472
+        except socket.timeout:
473
+            print("Timeout waiting for response to \"" + url + "\"")
474
+            return "timeout"
473 475
 
474 476
     def sendPostRequest(self, host, key, path, content):
475 477
         headers = {
@@ -560,7 +562,7 @@ class OctoTray():
560 562
 
561 563
     def getMethod(self, host, key):
562 564
         r = self.sendGetRequest(host, key, "plugin/psucontrol")
563
-        if r == "error":
565
+        if r == "timeout":
564 566
             return "unknown"
565 567
 
566 568
         try:
@@ -571,7 +573,7 @@ class OctoTray():
571 573
             pass
572 574
 
573 575
         r = self.sendGetRequest(host, key, "system/commands/custom")
574
-        if r == "error":
576
+        if r == "timeout":
575 577
             return "unknown"
576 578
 
577 579
         try:

Loading…
İptal
Kaydet