Skip to content

Commit 4eb3354

Browse files
authored
Merge pull request #224 from tamland/168-include-api-response-on-error
Include request response on HTTP error
2 parents 8b3fba3 + dad0019 commit 4eb3354

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

tidalapi/request.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def basic_request(
8080
headers["authorization"] = (
8181
self.session.token_type + " " + self.session.access_token
8282
)
83-
url = urljoin(self.session.config.api_location, path)
83+
url = urljoin(self.session.config.api_v1_location, path)
8484
request = self.session.request_session.request(
8585
method, url, params=request_params, data=data, headers=headers
8686
)
@@ -128,7 +128,12 @@ def request(
128128

129129
request = self.basic_request(method, path, params, data, headers)
130130
log.debug("request: %s", request.request.url)
131-
request.raise_for_status()
131+
try:
132+
request.raise_for_status()
133+
except Exception as e:
134+
print("Got exception", e)
135+
print("Response was", e.response)
136+
print("Response json was", e.response.json())
132137
if request.content:
133138
log.debug("response: %s", json.dumps(request.json(), indent=4))
134139
return request

tidalapi/session.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import concurrent.futures
2323
import datetime
2424
import json
25+
import locale
2526
import logging
2627
import random
2728
import time
@@ -94,7 +95,8 @@ class Config:
9495
Additionally, num_videos will turn into num_tracks in playlists.
9596
"""
9697

97-
api_location: str = "https://api.tidal.com/v1/"
98+
api_v1_location: str = "https://api.tidal.com/v1/"
99+
api_v2_location: str = "https://api.tidal.com/v2/"
98100
api_token: str
99101
client_id: str
100102
client_secret: str
@@ -382,7 +384,7 @@ def login(self, username: str, password: str) -> bool:
382384
:param password: The password to your TIDAL account
383385
:return: Returns true if we think the login was successful.
384386
"""
385-
url = urljoin(self.config.api_location, "login/username")
387+
url = urljoin(self.config.api_v1_location, "login/username")
386388
headers: dict[str, str] = {"X-Tidal-Token": self.config.api_token}
387389
payload = {
388390
"username": username,

0 commit comments

Comments
 (0)