Skip to content

Commit 4887a9a

Browse files
author
erenes
committed
Fix: Use urllib to combine urls (OpenTTD#5)
1 parent 5138022 commit 4887a9a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

bananas_cli/session.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import aiohttp
22
import logging
3+
import urllib.parse
34

45
from tusclient.client import TusClient
56
from tusclient.exceptions import TusCommunicationError
@@ -38,27 +39,29 @@ async def _read_response(self, response):
3839
return response.status, data
3940

4041
async def get(self, url):
41-
response = await self.session.get(f"{self.api_url}{url}", headers=self._headers, allow_redirects=False)
42+
full_url = urllib.parse.urljoin(self.api_url, url)
43+
response = await self.session.get(full_url, headers=self._headers, allow_redirects=False)
4244
return await self._read_response(response)
4345

4446
async def post(self, url, json):
45-
response = await self.session.post(
46-
f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False
47-
)
47+
full_url = urllib.parse.urljoin(self.api_url, url)
48+
response = await self.session.post(full_url, json=json, headers=self._headers, allow_redirects=False)
4849
return await self._read_response(response)
4950

5051
async def put(self, url, json):
51-
response = await self.session.put(
52-
f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False
53-
)
52+
full_url = urllib.parse.urljoin(self.api_url, url)
53+
response = await self.session.put(full_url, json=json, headers=self._headers, allow_redirects=False)
5454
return await self._read_response(response)
5555

5656
def tus_upload(self, upload_token, fullpath, filename):
57-
tus = TusClient(f"{self.tus_url}/new-package/tus/")
57+
full_url = urllib.parse.urljoin(self.tus_url, "/new-package/tus/")
58+
tus = TusClient(full_url)
5859

5960
try:
6061
uploader = tus.uploader(
61-
fullpath, chunk_size=UPLOAD_CHUNK_SIZE, metadata={"filename": filename, "upload-token": upload_token}
62+
fullpath,
63+
chunk_size=UPLOAD_CHUNK_SIZE,
64+
metadata={"filename": filename, "upload-token": upload_token},
6265
)
6366
uploader.upload()
6467
except TusCommunicationError:

0 commit comments

Comments
 (0)