diff --git a/src/taskgraph/util/taskcluster.py b/src/taskgraph/util/taskcluster.py index fdc9ce414..cebc4e5da 100644 --- a/src/taskgraph/util/taskcluster.py +++ b/src/taskgraph/util/taskcluster.py @@ -143,7 +143,7 @@ def _handle_artifact(path, response): if path.endswith(".json"): return response.json() if path.endswith(".yml"): - return yaml.load_stream(response.text) + return yaml.load_stream(response.content) response.raw.read = functools.partial(response.raw.read, decode_content=True) return response.raw diff --git a/test/test_util_taskcluster.py b/test/test_util_taskcluster.py index f79b2a428..39f604a78 100644 --- a/test/test_util_taskcluster.py +++ b/test/test_util_taskcluster.py @@ -154,6 +154,21 @@ def test_get_artifact(responses, root_url): ) assert tc.get_artifact(tid, "artifact.yml") == {"foo": "bar"} + responses.add( + responses.GET, + f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.yml", + body=b"foo: \xe2\x81\x83", + ) + assert tc.get_artifact(tid, "artifact.yml") == {"foo": b"\xe2\x81\x83".decode()} + + responses.add( + responses.GET, + f"{root_url}/api/queue/v1/task/{tid}/artifacts/artifact.yml", + body=b"foo: \xe2\x81\x83".decode().encode("utf-16"), + headers={"Content-Type": "text/yaml; charset=utf-16"}, + ) + assert tc.get_artifact(tid, "artifact.yml") == {"foo": b"\xe2\x81\x83".decode()} + def test_list_artifact(responses, root_url): tid = 123