Spaces:
Sleeping
Sleeping
cdborinstein commited on
Commit ·
4801e87
1
Parent(s): 3a0caf3
Fix user map parsing for different API response formats
Browse files- backup_to_hub.py +6 -1
backup_to_hub.py
CHANGED
|
@@ -71,7 +71,12 @@ def get_user_map(headers):
|
|
| 71 |
req = urllib.request.Request(f"{ARGILLA_API_URL}/api/v1/users", headers=headers)
|
| 72 |
with urllib.request.urlopen(req, timeout=30) as resp:
|
| 73 |
users_data = json.loads(resp.read().decode())
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
user_map[user["id"]] = user["username"]
|
| 76 |
except Exception as e:
|
| 77 |
print(f"Warning: Could not fetch users: {e}", flush=True)
|
|
|
|
| 71 |
req = urllib.request.Request(f"{ARGILLA_API_URL}/api/v1/users", headers=headers)
|
| 72 |
with urllib.request.urlopen(req, timeout=30) as resp:
|
| 73 |
users_data = json.loads(resp.read().decode())
|
| 74 |
+
# Handle both list and dict (with "items" key) response formats
|
| 75 |
+
if isinstance(users_data, dict):
|
| 76 |
+
users_list = users_data.get("items", [])
|
| 77 |
+
else:
|
| 78 |
+
users_list = users_data
|
| 79 |
+
for user in users_list:
|
| 80 |
user_map[user["id"]] = user["username"]
|
| 81 |
except Exception as e:
|
| 82 |
print(f"Warning: Could not fetch users: {e}", flush=True)
|