#2256 python: raise exception when for repeated ConnectionErrors
Merged 2 years ago by frostyx. Opened 2 years ago by praiskup.
Unknown source fix-2235-again  into  main

file modified
+8 -6
@@ -54,15 +54,17 @@

          for i in range(1, self.connection_attempts + 1):

              try:

                  response = requests.request(**request_params)

+                 if response.status_code == 401 and i < self.connection_attempts:

+                     # try to authenticate again, don't sleep!

+                     self._update_auth_params(request_params, auth, reauth=True)

+                     continue

+                 # Return the response object (even for non-200 status codes!)

+                 return response

              except requests.exceptions.ConnectionError:

                  if i < self.connection_attempts:

                      time.sleep(sleep)

-             else:

-                 if response.status_code == 401:

-                     self._update_auth_params(request_params, auth, reauth=True)

-                     continue

-                 break

-         return response

+ 

+         raise CoprRequestException("Unable to connect to {0}.".format(self.api_base_url))

  

      def _request_params(self, endpoint, method=GET, data=None, params=None,

                          headers=None, auth=None):

This situation led to
UnboundLocalError: local variable 'response' referenced before assignment
while attempting to return the not-yet-set response object.

Complements: 5572bff
Fixes: #2235
Relates: #2218

Build succeeded.

rebased onto 884daf798600adb3c354ae3a453f706f6611c656

2 years ago

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging pagure.io/copr/copr for 2256,884daf798600adb3c354ae3a453f706f6611c656

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging pagure.io/copr/copr for 2256,884daf798600adb3c354ae3a453f706f6611c656

rebased onto a1c9cc5

2 years ago

Build succeeded.

Pull-Request has been merged by frostyx

2 years ago
Metadata