From c7c4850e1434ea166df1076bc7c4d217cdbaa27a Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Fri, 2 Oct 2026 15:18:31 +0800 Subject: [PATCH] Fix AutoDL GET request parameters --- controller.py | 12 ++++++++++-- tests/test_controller.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/controller.py b/controller.py index 04013f7..ea99d48 100644 --- a/controller.py +++ b/controller.py @@ -14,6 +14,7 @@ import sys import tempfile import time import urllib.error +import urllib.parse import urllib.request from dataclasses import dataclass from pathlib import Path @@ -144,9 +145,16 @@ class AutoDLClient: self.token = token def request(self, method: str, path: str, body: dict[str, Any]) -> Any: + url = f"{API_BASE}{path}" + data: bytes | None + if method == "GET": + url = f"{url}?{urllib.parse.urlencode(body)}" + data = None + else: + data = json.dumps(body).encode() request = urllib.request.Request( - f"{API_BASE}{path}", - data=json.dumps(body).encode(), + url, + data=data, method=method, headers={"Authorization": self.token, "Content-Type": "application/json"}, ) diff --git a/tests/test_controller.py b/tests/test_controller.py index b37b743..a098e69 100644 --- a/tests/test_controller.py +++ b/tests/test_controller.py @@ -11,6 +11,19 @@ import controller class ControllerTests(unittest.TestCase): + def test_get_requests_encode_parameters_in_the_query_string(self): + response = io.BytesIO(json.dumps({"code": "Success", "data": "stopped"}).encode()) + client = controller.AutoDLClient("test-token") + with mock.patch.object( + controller.urllib.request, "urlopen", return_value=response + ) as urlopen: + self.assertEqual(client.status("pro-test"), "stopped") + + request = urlopen.call_args.args[0] + self.assertEqual(request.method, "GET") + self.assertIsNone(request.data) + self.assertTrue(request.full_url.endswith("?instance_uuid=pro-test")) + def test_runner_download_uses_explicit_user_agent(self): payload = b"test-runner" with tempfile.TemporaryDirectory() as directory: