Skip to content

Commit

Permalink
Merge pull request #224 from tamland/168-include-api-response-on-error
Browse files Browse the repository at this point in the history
Include request response on HTTP error
  • Loading branch information
tehkillerbee authored Jan 26, 2024
2 parents 8b3fba3 + dad0019 commit 4eb3354
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions tidalapi/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tidalapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import concurrent.futures
import datetime
import json
import locale
import logging
import random
import time
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4eb3354

Please sign in to comment.