Skip to content

Commit f6d57cb

Browse files
committed
Fix: Use urllib to combine urls (OpenTTD#5)
1 parent a0273ac commit f6d57cb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

bananas_cli/session.py

+9-4
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,23 +37,27 @@ 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):
45+
full_url = urllib.parse.urljoin(self.api_url, url)
4346
response = await self.session.post(
44-
f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False
47+
full_url, json=json, headers=self._headers, allow_redirects=False
4548
)
4649
return await self._read_response(response)
4750

4851
async def put(self, url, json):
52+
full_url = urllib.parse.urljoin(self.api_url, url)
4953
response = await self.session.put(
50-
f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False
54+
full_url, json=json, headers=self._headers, allow_redirects=False
5155
)
5256
return await self._read_response(response)
5357

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

5762
try:
5863
uploader = tus.uploader(

0 commit comments

Comments
 (0)