fix: use get_running_loop, guard updatedAt, pass auth on wait_ready
This commit is contained in:
+4
-3
@@ -36,12 +36,13 @@ class MihomoClient:
|
||||
|
||||
await self.trigger_provider_refresh(name)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.get_running_loop()
|
||||
deadline = loop.time() + timeout
|
||||
while loop.time() < deadline:
|
||||
await asyncio.sleep(1)
|
||||
data = await self.get_provider(name)
|
||||
if data.get("updatedAt", "") != initial_ts:
|
||||
new_ts = data.get("updatedAt")
|
||||
if new_ts is not None and new_ts != initial_ts:
|
||||
return data.get("proxies", [])
|
||||
|
||||
raise TimeoutError(f"Provider {name!r} did not refresh within {timeout}s")
|
||||
@@ -60,7 +61,7 @@ class MihomoClient:
|
||||
for i in range(retries):
|
||||
try:
|
||||
async with httpx.AsyncClient() as c:
|
||||
resp = await c.get(f"{self._base_url}/version", timeout=3.0)
|
||||
resp = await c.get(f"{self._base_url}/version", timeout=3.0, headers=self._headers)
|
||||
resp.raise_for_status()
|
||||
return
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user