From 888e1c4cff4bdd9005b7d954e3081d75f2ed8feb Mon Sep 17 00:00:00 2001 From: tehkillerbee Date: Fri, 26 Jan 2024 18:42:20 +0100 Subject: [PATCH 1/3] Include request response on error. Print as warning. --- tidalapi/request.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tidalapi/request.py b/tidalapi/request.py index 90548d1..9be7358 100644 --- a/tidalapi/request.py +++ b/tidalapi/request.py @@ -128,7 +128,12 @@ def request( request = self.basic_request(method, path, params, data, headers) log.debug("request: %s", request.request.url) - request.raise_for_status() + try: + request.raise_for_status() + except Exception as e: + print("Got exception", e) + print("Response was", e.response) + print("Response json was", e.response.json()) if request.content: log.debug("response: %s", json.dumps(request.json(), indent=4)) return request From 60027f32201380ed0038bff929efd693dede5598 Mon Sep 17 00:00:00 2001 From: tehkillerbee Date: Fri, 26 Jan 2024 18:43:06 +0100 Subject: [PATCH 2/3] Add path to both v1 and v2 api's --- tidalapi/request.py | 2 +- tidalapi/session.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tidalapi/request.py b/tidalapi/request.py index 9be7358..ff25469 100644 --- a/tidalapi/request.py +++ b/tidalapi/request.py @@ -80,7 +80,7 @@ def basic_request( headers["authorization"] = ( self.session.token_type + " " + self.session.access_token ) - url = urljoin(self.session.config.api_location, path) + url = urljoin(self.session.config.api_v1_location, path) request = self.session.request_session.request( method, url, params=request_params, data=data, headers=headers ) diff --git a/tidalapi/session.py b/tidalapi/session.py index e5ba1ed..765512d 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -26,6 +26,7 @@ import random import time import uuid +import locale from dataclasses import dataclass from enum import Enum from pathlib import Path @@ -94,7 +95,8 @@ class Config: Additionally, num_videos will turn into num_tracks in playlists. """ - api_location: str = "https://api.tidal.com/v1/" + api_v1_location: str = "https://api.tidal.com/v1/" + api_v2_location: str = "https://api.tidal.com/v2/" api_token: str client_id: str client_secret: str @@ -382,7 +384,7 @@ def login(self, username: str, password: str) -> bool: :param password: The password to your TIDAL account :return: Returns true if we think the login was successful. """ - url = urljoin(self.config.api_location, "login/username") + url = urljoin(self.config.api_v1_location, "login/username") headers: dict[str, str] = {"X-Tidal-Token": self.config.api_token} payload = { "username": username, From dad0019d22f0a185985c28eab1520e036a1a255b Mon Sep 17 00:00:00 2001 From: tehkillerbee Date: Fri, 26 Jan 2024 18:45:28 +0100 Subject: [PATCH 3/3] Fix formatting --- tidalapi/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidalapi/session.py b/tidalapi/session.py index 765512d..c55b590 100644 --- a/tidalapi/session.py +++ b/tidalapi/session.py @@ -22,11 +22,11 @@ import concurrent.futures import datetime import json +import locale import logging import random import time import uuid -import locale from dataclasses import dataclass from enum import Enum from pathlib import Path