Skip to content

Commit 535ce62

Browse files
author
erenes
committed
Fix: Use urllib to combine urls (OpenTTD#5)
1 parent a0273ac commit 535ce62

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
@@ -36,27 +37,29 @@ async def _read_response(self, response):
3637
return response.status, data
3738

3839
async def get(self, url):
39-
response = await self.session.get(f"{self.api_url}{url}", headers=self._headers, allow_redirects=False)
40+
full_url = urllib.parse.urljoin(self.api_url, url)
41+
response = await self.session.get(full_url, headers=self._headers, allow_redirects=False)
4042
return await self._read_response(response)
4143

4244
async def post(self, url, json):
43-
response = await self.session.post(
44-
f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False
45-
)
45+
full_url = urllib.parse.urljoin(self.api_url, url)
46+
response = await self.session.post(full_url, json=json, headers=self._headers, allow_redirects=False)
4647
return await self._read_response(response)
4748

4849
async def put(self, url, json):
49-
response = await self.session.put(
50-
f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False
51-
)
50+
full_url = urllib.parse.urljoin(self.api_url, url)
51+
response = await self.session.put(full_url, json=json, headers=self._headers, allow_redirects=False)
5252
return await self._read_response(response)
5353

5454
def tus_upload(self, upload_token, fullpath, filename):
55-
tus = TusClient(f"{self.tus_url}/new-package/tus/")
55+
full_url = urllib.parse.urljoin(self.tus_url, "/new-package/tus/")
56+
tus = TusClient(full_url)
5657

5758
try:
5859
uploader = tus.uploader(
59-
fullpath, chunk_size=UPLOAD_CHUNK_SIZE, metadata={"filename": filename, "upload-token": upload_token}
60+
fullpath,
61+
chunk_size=UPLOAD_CHUNK_SIZE,
62+
metadata={"filename": filename, "upload-token": upload_token},
6063
)
6164
uploader.upload()
6265
except TusCommunicationError:

0 commit comments

Comments
 (0)