diff --git a/pyVoIP/SIP/client.py b/pyVoIP/SIP/client.py index 946224f..0490ae8 100644 --- a/pyVoIP/SIP/client.py +++ b/pyVoIP/SIP/client.py @@ -1237,7 +1237,9 @@ def bye(self, request: SIPMessage) -> None: ), ) response = SIPMessage.from_bytes(conn.recv(8192)) - if response.status == ResponseCode(401): + if response.status == ResponseCode(401) or response.status == ResponseCode( + 407 + ): # Requires password auth = self.gen_authorization(response) message = message.replace( @@ -1283,7 +1285,9 @@ def __deregister(self) -> bool: first_response = response conn.close() # Regardless of the response, the dialog is over - if response.status == ResponseCode(401): + if response.status == ResponseCode(401) or response.status == ResponseCode( + 407 + ): # Unauthorized, likely due to being password protected. password_request = self.gen_register(response, deregister=True) conn = self.send(password_request) @@ -1297,11 +1301,6 @@ def __deregister(self) -> bool: # with new urn:uuid or reply with expire 0 self._handle_bad_request() - elif response.status == ResponseCode(407): - # Proxy Authentication Required - # TODO: implement - debug("Proxy auth required") - elif response.status == ResponseCode(500): # We raise so the calling function can sleep and try again raise RetryRequiredError( @@ -1311,7 +1310,9 @@ def __deregister(self) -> bool: elif response.status == ResponseCode.OK: return True - elif response.status == ResponseCode(401): + elif response.status == ResponseCode(401) or response.status == ResponseCode( + 407 + ): # At this point, it's reasonable to assume that # this is caused by invalid credentials. debug("=" * 50) @@ -1384,7 +1385,9 @@ def __register(self) -> bool: first_response = response conn.close() # Regardless of the response, the dialog is over - if response.status == ResponseCode(401): + if response.status == ResponseCode(401) or response.status == ResponseCode( + 407 + ): # Unauthorized, likely due to being password protected. password_request = self.gen_register(response) conn = self.send(password_request) @@ -1398,11 +1401,6 @@ def __register(self) -> bool: # with new urn:uuid or reply with expire 0 self._handle_bad_request() - elif response.status == ResponseCode(407): - # Proxy Authentication Required - # TODO: implement - debug("Proxy auth required") - elif response.status == ResponseCode(500): # We raise so the calling function can sleep and try again raise RetryRequiredError("Received a 500 error when registering.") @@ -1410,7 +1408,9 @@ def __register(self) -> bool: elif response.status == ResponseCode.OK: return True - elif response.status == ResponseCode(401): + elif response.status == ResponseCode(401) or response.status == ResponseCode( + 407 + ): # At this point, it's reasonable to assume that # this is caused by invalid credentials. debug("=" * 50)