johannes-ws commented on issue #29934:
URL: https://github.com/apache/superset/issues/29934#issuecomment-3138667332

   I got a same message error, but in my case i success get access token, but 
error when would post API
   
       import requests
       import json
       import os
   
       # --- Configuration ---
       # For security, use environment variables in production environments.
       SUPERSET_URL = "http://127.0.0.1:8088/";
       ADMIN_USER = os.getenv("SUPERSET_ADMIN_USER", "admin")
       ADMIN_PASSWORD = os.getenv("SUPERSET_ADMIN_PASSWORD", "admin")
   
       # --- New Role & User Details ---
       NEW_ROLE_NAME = "Financial Analyst"
       NEW_ROLE_PERMISSIONS = ["can read on Dashboard", "can read on Chart"]
   
       NEW_USER_USERNAME = "dina.finance"
       NEW_USER_FIRSTNAME = "Dina"
       NEW_USER_LASTNAME = "Putri"
       NEW_USER_EMAIL = "dina.fina...@example.com"
       NEW_USER_PASSWORD = "SecureStrongPassword456!"
   
       # Error handler function
       def handle_error(response):
           """Prints error message from API response and exits."""
           try:
               error_details = response.json()
               print(f"āŒ Failed: Status {response.status_code} - 
{error_details.get('message', response.text)}")
           except json.JSONDecodeError:
               print(f"āŒ Failed: Status {response.status_code} - 
{response.text}")
           exit()
   
       def main():
           """Main function to execute the process."""
           access_token = None
   
           # Use a session object for efficient multiple requests
           session = requests.Session()
   
           # 1. Login and get access token
           print(f"šŸ”‘ Attempting to log in as '{ADMIN_USER}'...")
           try:
               login_payload = {
                   "username": ADMIN_USER,
                   "password": ADMIN_PASSWORD,
                   "provider": "db"
               }
               response = session.post(f"{SUPERSET_URL}/api/v1/security/login", 
json=login_payload, timeout=10)
               
               if response.status_code != 200:
                   handle_error(response)
                   
               access_token = response.json().get("access_token")
               if not access_token:
                   print("āŒ Access token not found in response.")
                   exit()
                   
               print("āœ… Successfully retrieved token.")
               # Set Authorization header for subsequent requests
               session.headers.update({"Authorization": f"Bearer 
{access_token}"})
   
           except requests.exceptions.RequestException as e:
               print(f"āŒ Connection error during login: {e}")
               exit()
   
           # 2. Create or get Role
           print(f"šŸ› ļø Checking for role '{NEW_ROLE_NAME}'...")
           role_id = None
           role_payload = {"name": NEW_ROLE_NAME, "permissions": 
NEW_ROLE_PERMISSIONS}
           
           try:
               response = 
session.post(f"{SUPERSET_URL}/api/v1/security/roles/", json=role_payload)
               if response.status_code == 201:
                   role_id = response.json()["result"]["id"]
                   print(f"āœ… Role '{NEW_ROLE_NAME}' successfully created with 
ID: {role_id}")
               elif response.status_code == 409:
                   print(f"ā„¹ļø Role '{NEW_ROLE_NAME}' already exists. Searching 
for ID...")
                   params = {"q": json.dumps({"filters": [{"col": "name", 
"opr": "eq", "value": NEW_ROLE_NAME}]})}
                   response_get = 
session.get(f"{SUPERSET_URL}/api/v1/security/roles/", params=params)
                   if response_get.status_code == 200 and 
response_get.json()["count"] > 0:
                       role_id = response_get.json()["result"][0]["id"]
                       print(f"āœ… Role found with ID: {role_id}")
                   else:
                       print("āŒ Failed to find ID for existing role.")
                       exit()
               else:
                   handle_error(response)
   
           except requests.exceptions.RequestException as e:
               print(f"āŒ Connection error while creating role: {e}")
               exit()
   
           # 3. Create new user
           if role_id:
               print(f"šŸ‘¤ Creating user '{NEW_USER_USERNAME}'...")
               user_payload = {
                   "first_name": NEW_USER_FIRSTNAME,
                   "last_name": NEW_USER_LASTNAME,
                   "username": NEW_USER_USERNAME,
                   "email": NEW_USER_EMAIL,
                   "password": NEW_USER_PASSWORD,
                   "active": True,
                   "roles": [role_id]
               }
               try:
                   response = 
session.post(f"{SUPERSET_URL}/api/v1/security/users/", json=user_payload)
                   if response.status_code != 201:
                       handle_error(response)
                   
                   print(f"āœ… User '{NEW_USER_USERNAME}' successfully created.")
               except requests.exceptions.RequestException as e:
                   print(f"āŒ Connection error while creating user: {e}")
                   exit()
           else:
               print("āŒ Cannot proceed with user creation because role ID was 
not found.")
   
           print("\nšŸŽ‰ Process Completed!")
   
       if __name__ == "__main__":
           main()
   
   When i run <code>python setup_superset.py</code> it gave this output
   
        šŸ”‘ Attempting to log in as 'admin'...
        āœ… Successfully retrieved token.
        šŸ› ļø Checking for role 'Financial Analyst'...
        āŒ Failed: Status 404 - {"errors": [{"message": "404 Not Found: The 
requested URL was not found on the server. If you entered the URL manually 
please check your spelling and try again.", "error_type": 
"GENERIC_BACKEND_ERROR", "level": "error", "extra": {"issue_codes": [{"code": 
1011, "message": "Issue 1011 - Superset encountered an unexpected error."}]}}]}
   
   Any solution about that? @rusackas 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to