|
6 | 6 | import copy |
7 | 7 | import datetime |
8 | 8 | import functools |
| 9 | +import io |
9 | 10 | import logging |
10 | 11 | import os |
11 | 12 | from typing import Dict, List, Union |
@@ -70,12 +71,30 @@ def get_taskcluster_client(service: str): |
70 | 71 |
|
71 | 72 |
|
72 | 73 | def _handle_artifact(path, response): |
| 74 | + # When taskcluster client returns non-JSON responses, it wraps them in {"response": <Response>} |
| 75 | + # When it returns JSON, it's already parsed |
| 76 | + if isinstance(response, dict) and "response" in response: |
| 77 | + response = response["response"] |
| 78 | + |
73 | 79 | if path.endswith(".json"): |
| 80 | + # If response is already a dict (parsed JSON), return it directly |
| 81 | + if isinstance(response, dict): |
| 82 | + return response |
74 | 83 | return response.json() |
75 | 84 |
|
76 | 85 | if path.endswith(".yml"): |
77 | 86 | return yaml.load_stream(response.content) |
78 | 87 |
|
| 88 | + # For non-JSON/YAML content, return raw response content |
| 89 | + if getattr(response, "raw", None): |
| 90 | + # Try to read from raw, but if it's empty, fall back to content |
| 91 | + content = response.raw.read() |
| 92 | + if not content and hasattr(response, "content"): |
| 93 | + content = response.content |
| 94 | + return io.BytesIO(content) |
| 95 | + elif hasattr(response, "content"): |
| 96 | + return io.BytesIO(response.content) |
| 97 | + |
79 | 98 | response.raw.read = functools.partial(response.raw.read, decode_content=True) |
80 | 99 | return response.raw |
81 | 100 |
|
|
0 commit comments