Skip to content

Commit b274066

Browse files
authored
fix: incorrect twirp url (#82)
1 parent 1c8d59c commit b274066

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

livekit-api/livekit/api/_twirp_client.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
import aiohttp
1818
from google.protobuf.message import Message
19+
from urllib.parse import urlparse
1920

20-
DEFAULT_PREFIX = "/twirp"
21+
DEFAULT_PREFIX = "twirp"
2122

2223

2324
class TwirpError(Exception):
@@ -52,7 +53,9 @@ class TwirpErrorCode:
5253

5354
class TwirpClient:
5455
def __init__(self, host: str, pkg: str, prefix: str = DEFAULT_PREFIX) -> None:
55-
self.host = host
56+
parse_res = urlparse(host)
57+
host = f"http://{parse_res.netloc}/{parse_res.path}"
58+
self.host = host.rstrip("/")
5659
self.pkg = pkg
5760
self.prefix = prefix
5861
self.session = aiohttp.ClientSession()
@@ -69,8 +72,8 @@ async def request(
6972
headers["Content-Type"] = "application/protobuf"
7073

7174
serialized_data = data.SerializeToString()
72-
async with self.session.post(
73-
url, headers=headers, data=serialized_data
75+
async with self.session.request(
76+
"post", url, headers=headers, data=serialized_data
7477
) as resp:
7578
if resp.status == 200:
7679
return response_class.FromString(await resp.read())

0 commit comments

Comments
 (0)