mirror of
https://github.com/TronoSfera/backup_service.git
synced 2026-05-18 10:03:32 +03:00
Merge pull request #5 from TronoSfera/codex/fix-connection-error-for-api-login
Handle connection errors during client login
This commit is contained in:
commit
477280a9e5
1 changed files with 7 additions and 1 deletions
|
|
@ -139,7 +139,13 @@ class BackupClient:
|
|||
url = f"{self.server_url}/api/login"
|
||||
data = {"username": self.username, "password": self.password}
|
||||
# Use form-encoded data as required by OAuth2PasswordRequestForm
|
||||
try:
|
||||
response = requests.post(url, data=data)
|
||||
except requests.exceptions.RequestException as exc:
|
||||
raise RuntimeError(
|
||||
"Failed to connect to the backup server. "
|
||||
f"Verify the server is running and SERVER_URL is correct ({self.server_url})."
|
||||
) from exc
|
||||
if response.status_code != 200:
|
||||
raise RuntimeError(f"Failed to login: {response.text}")
|
||||
token = response.json()["access_token"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue