From 183959f4a0b2500613193e263ba647111f4dcb3c Mon Sep 17 00:00:00 2001 From: sit002 Date: Tue, 2 Dec 2025 10:01:40 +0800 Subject: [PATCH] fix: handle list response when checking file existence --- .autograde/upload_metadata.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.autograde/upload_metadata.py b/.autograde/upload_metadata.py index 89dec80..8341ac5 100644 --- a/.autograde/upload_metadata.py +++ b/.autograde/upload_metadata.py @@ -98,8 +98,15 @@ def main() -> int: try: with urllib.request.urlopen(get_req) as resp: existing_file = json.loads(resp.read().decode()) - sha = existing_file.get("sha") - print(f"File exists, updating (sha: {sha})") + # API may return a list (directory contents) or dict (single file) + if isinstance(existing_file, dict): + sha = existing_file.get("sha") + print(f"File exists, updating (sha: {sha})") + elif isinstance(existing_file, list): + # Response is a directory listing, file doesn't exist at this exact path + print(f"Path is a directory or file not found in expected format") + else: + print(f"Unexpected response type: {type(existing_file)}") except urllib.error.HTTPError as e: if e.code != 404: print(f"Error checking file existence: {e}", file=sys.stderr)