sbernauer commented on PR #26889:
URL: https://github.com/apache/superset/pull/26889#issuecomment-1932227050

   I used the following Python script to export and import the attached zip
   ```
   import logging
   import requests
   
   base_url = "http://127.0.0.1:8088";
   superset_username = "admin"
   superset_password =  "admin"
   
   logging.basicConfig(level=logging.INFO)
   logging.info("Starting setup of Superset")
   
   logging.info("Getting access token from /api/v1/security/login")
   session = requests.session()
   access_token = session.post(f"{base_url}/api/v1/security/login", 
json={"username": superset_username, "password": superset_password, "provider": 
"db", "refresh": True}).json()['access_token']
   # print(f"access_token: {access_token}")
   
   logging.info("Getting csrf token from /api/v1/security/csrf_token")
   csrf_token = session.get(f"{base_url}/api/v1/security/csrf_token", 
headers={"Authorization": f"Bearer {access_token}"}).json()["result"]
   # print(f"csrf_token: {csrf_token}")
   
   headers = {
       "accept": "application/json",
       "Authorization": f"Bearer {access_token}",
       "X-CSRFToken": csrf_token,
   }
   
   # To retrieve all of the assets (datasources, datasets, charts and 
dashboards) run the following commands
   # logging.info("Exporting all assets")
   # result = session.get(f"{base_url}/api/v1/assets/export", headers=headers)
   # assert result.status_code == 200
   # with open("superset-assets.zip", "wb") as f:
   #     f.write(result.content)
   
   #########################
   # IMPORTANT
   #########################
   # The exported zip file had to be modified, otherwise we get:
   # <Response [422]>
   # {"errors": [{"message": "Error importing assets", "error_type": 
"GENERIC_COMMAND_ERROR", "level": "warning", "extra": {"databases/Trino.yaml": 
{"extra": {"disable_data_preview": ["Unknown field."]}}, "issue_codes": 
[{"code": 1010, "message": "Issue 1010 - Superset encountered an error while 
running a command."}]}}]}
   #
   # The file databases/Trino.yaml was modified and the attribute 
"extra.disable_data_preview" was removed
   #########################
   logging.info("Importing all assets")
   files = {
       "bundle": ("superset-assets.zip", open("superset-assets.zip", "rb")),
   }
   data = {
       "passwords": '{"databases/PostgreSQL.yaml": "admin"}'
   }
   result = session.post(f"{base_url}/api/v1/assets/import", headers=headers, 
files=files, data=data)
   print(result)
   print(result.text)
   assert result.status_code == 200
   
   logging.info("Finished setup of Superset")
   ```
   
[assets_export_20240130T160948.zip](https://github.com/apache/superset/files/14195461/assets_export_20240130T160948.zip)
   


-- 
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