调用pythonkeloclak库API获取客户端时出现以下错误

2024-05-18 15:20:27 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我试图使用内置python库从KeyClope服务器获取客户机的代码

**from keycloak import KeycloakAdmin
keycloak_admin = KeycloakAdmin(server_url='https://server-url/auth',
                  username='admin',
                  password='xxxxx',
                  realm_name='master',
                  user_realm_name='xxxx',
                  client_id='admin-cli',
                  verify=True)**

# Get clients belonging to the realm Returns a list of clients belonging to the realm
**clients = keycloak_admin.get_clients()**

错误

File "d:\Python-Keycloak\keycloak-client.py", line 28, in <module>
    keycloak_admin = KeycloakAdmin(server_url='https://server-url/auth',
  File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\keycloak\keycloak_admin.py", line 96, in __init__
    self.get_token()
  File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\keycloak\keycloak_admin.py", line 1729, in get_token
    self._token = self.keycloak_openid.token(self.username, self.password, grant_type=grant_type)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\keycloak\keycloak_openid.py", line 201, in token
    return raise_error_from_response(data_raw, KeycloakGetError)
  File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\keycloak\exceptions.py", line 106, in raise_error_from_response
    raise error(error_message=message,
keycloak.exceptions.KeycloakGetError: 404: b'<html><head><title>Error</title></head><body>404 - Not Found</body></html>'

Tags: inpyselftokenurlserveradminlocal

热门问题