Fix UDM-SE authentication error by skipping meta.rc check for auth endpoint
The authentication endpoint /api/auth/login returns HTTP 200 with a different JSON response format than data endpoints. UDM-SE (UniFi OS) does not include the meta.rc field in authentication responses, causing false authentication failures. Changes: - Added skip_meta_check parameter to _request_json() method - Updated _login() to skip meta.rc validation for auth endpoint - Added debug logging to show actual API responses for troubleshooting Fixes authentication error: "UniFi API error: Unknown error" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d42fd83d5d
commit
c157595ee3
@ -48,7 +48,7 @@ class UnifiClient:
|
||||
self._login()
|
||||
|
||||
def _request_json(self, endpoint: str, method: str = 'GET',
|
||||
data: Optional[dict] = None) -> dict:
|
||||
data: Optional[dict] = None, skip_meta_check: bool = False) -> dict:
|
||||
"""
|
||||
Make a request to the UniFi API and return JSON response.
|
||||
|
||||
@ -56,6 +56,7 @@ class UnifiClient:
|
||||
endpoint: API endpoint path
|
||||
method: HTTP method (GET, POST, etc.)
|
||||
data: Optional data for POST requests
|
||||
skip_meta_check: Skip meta.rc validation (for auth endpoints)
|
||||
|
||||
Returns:
|
||||
dict: JSON response
|
||||
@ -80,10 +81,13 @@ class UnifiClient:
|
||||
except ValueError:
|
||||
raise UniFiDataError(f"Invalid JSON response from {endpoint}")
|
||||
|
||||
# Check for UniFi API error response
|
||||
if isinstance(json_response, dict):
|
||||
self.logger.debug(f"Response from {endpoint}: {json_response}")
|
||||
|
||||
# Check for UniFi API error response (skip for authentication endpoints)
|
||||
if not skip_meta_check and isinstance(json_response, dict):
|
||||
if json_response.get('meta', {}).get('rc') != 'ok':
|
||||
error_msg = json_response.get('meta', {}).get('msg', 'Unknown error')
|
||||
self.logger.debug(f"Meta check failed. Response: {json_response}")
|
||||
raise UniFiDataError(f"UniFi API error: {error_msg}")
|
||||
|
||||
return json_response
|
||||
@ -105,8 +109,11 @@ class UnifiClient:
|
||||
}
|
||||
|
||||
try:
|
||||
response = self._request_json('/api/auth/login', method='POST', data=login_data)
|
||||
self.logger.debug("Successfully authenticated with UniFi controller")
|
||||
# Skip meta.rc check for auth endpoint - UDM-SE uses different response format
|
||||
response = self._request_json('/api/auth/login', method='POST',
|
||||
data=login_data, skip_meta_check=True)
|
||||
self.logger.debug(f"Successfully authenticated with UniFi controller")
|
||||
self.logger.debug(f"Authentication response: {response}")
|
||||
|
||||
except UniFiDataError as e:
|
||||
self.logger.error(f"Authentication failed: {e}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user