Commits

Denilson Sá  committed 8df3edd

technicolor_gateway_adsl_info.py: Retrying once if the first request returns 401.

  • Participants
  • Parent commits 0d70b4a

Comments (0)

Files changed (1)

File technicolor_gateway_adsl_info.py

     # Explicit auth is not required, because the library can already read from
     # ~/.netrc.
     auth = (username, password) if username or password else None
-    r = requests.get(
-        url,
-        cookies={'language_flag': '0'},  # To force English language.
-        auth=auth
-    )
+
+    # For some weird reason, the first request always returns 401 Unauthorized.
+    # Retrying will work, and it will continue working for a couple of minutes.
+    for i in range(2):
+        r = requests.get(
+            url,
+            cookies={'language_flag': '0'},  # To force English language.
+            auth=auth
+        )
+        # If it returns 401, let's try once more.
+        if r.status_code != 401:
+            break
+
     r.raise_for_status()
     return r.text