From cc865e33fe0ac437d451bfc3c9aeb357f5ab050b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Mon, 30 Oct 2023 18:30:10 -0700 Subject: [PATCH] Update _twirp_client.py --- livekit-api/livekit/api/_twirp_client.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/livekit-api/livekit/api/_twirp_client.py b/livekit-api/livekit/api/_twirp_client.py index 9182afe0..8c7bb454 100644 --- a/livekit-api/livekit/api/_twirp_client.py +++ b/livekit-api/livekit/api/_twirp_client.py @@ -16,8 +16,9 @@ import aiohttp from google.protobuf.message import Message +from urllib.parse import urlparse -DEFAULT_PREFIX = "/twirp" +DEFAULT_PREFIX = "twirp" class TwirpError(Exception): @@ -52,7 +53,10 @@ class TwirpErrorCode: class TwirpClient: def __init__(self, host: str, pkg: str, prefix: str = DEFAULT_PREFIX) -> None: - self.host = host + parse_res = urlparse(host) + path = parse_res.path.strip("/") + host = f"http://{parse_res.netloc}/{parse_res.path}" + self.host = host.rstrip("/") self.pkg = pkg self.prefix = prefix self.session = aiohttp.ClientSession() @@ -69,8 +73,8 @@ async def request( headers["Content-Type"] = "application/protobuf" serialized_data = data.SerializeToString() - async with self.session.post( - url, headers=headers, data=serialized_data + async with self.session.request( + "post", url, headers=headers, data=serialized_data ) as resp: if resp.status == 200: return response_class.FromString(await resp.read())