Skip to content

Commit

Permalink
using urljoin instead of Path. Path caused an issue with removing for…
Browse files Browse the repository at this point in the history
…ward slashes after schema
  • Loading branch information
csbarnet committed Feb 3, 2025
1 parent d2cc838 commit 5b761d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions vast_api_client/abstract_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from urllib.parse import urljoin
import requests


Expand All @@ -24,11 +25,11 @@ def _send_get_request(self, endpoint, params=None, retries=2):
if self.token is None and self.refresh_token is not None:
self.renew_token(self.refresh_token)

r = requests.get(Path(self.url, endpoint).as_posix(),
r = requests.get(urljoin(self.url, endpoint),
params=params if not None else {},
headers=self._get_headers(),
verify=False,
timeout=10)
verify=True,
timeout=30)
try:
r.raise_for_status()
except requests.exceptions.HTTPError as e:
Expand Down Expand Up @@ -56,10 +57,10 @@ def _send_body(self, http_method, endpoint, payload, headers=None, skip_auth=Fal
headers = headers if headers is not None else {}
headers.update({'Content-Type': 'application/json'})

r = requests.request(http_method, Path(self.url, endpoint).as_posix(),
r = requests.request(http_method, urljoin(self.url, endpoint),
json=payload,
headers=self._get_headers(headers, skip_auth=skip_auth),
verify=False,
verify=True,
timeout=20)
r.raise_for_status()
return r.json()
Expand All @@ -70,9 +71,9 @@ def _send_delete_request(self, endpoint, body=None):
if self.token is None and self.refresh_token is not None:
self.renew_token(self.refresh_token)

r = requests.delete(Path(self.url, endpoint).as_posix(),
r = requests.delete(urljoin(self.url, endpoint),
headers=self._get_headers(),
verify=False,
verify=True,
timeout=10)

r.raise_for_status()
Expand Down
3 changes: 2 additions & 1 deletion vast_api_client/vast_api_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from urllib.parse import urljoin
from vast_api_client.models import (PathBody, ViewCreate, QuotaCreate, FolderCreateOrUpdate,
QuotaUpdate, ProtectedPathCreate, ProtocolEnum, PolicyEnum)
from vast_api_client.utils import ResourceExistsError
Expand All @@ -20,7 +21,7 @@ def __init__(self, host: str, user: str = None, password: str = None, token: str
:param refresh_token:
"""
self.host = host
self.url = Path(f'https://{host}', 'api/latest')
self.url = urljoin(f'https://{host}', 'api/latest')

if token is not None and refresh_token is not None:
self.token = token
Expand Down

0 comments on commit 5b761d9

Please sign in to comment.