Add more detail to 4xx error messages
This commit is contained in:
parent
302c95ff6f
commit
8a87dfc65f
1 changed files with 11 additions and 9 deletions
|
|
@ -93,12 +93,11 @@ class YTMusic(BrowsingMixin, WatchMixin, LibraryMixin, PlaylistsMixin, UploadsMi
|
||||||
|
|
||||||
# verify authentication credentials work
|
# verify authentication credentials work
|
||||||
if auth:
|
if auth:
|
||||||
self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
|
try:
|
||||||
response = self._send_request('guide', {})
|
self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
|
||||||
if 'error' in response:
|
except KeyError:
|
||||||
raise Exception(
|
raise Exception("Your cookie is missing the required value __Secure-3PAPISID")
|
||||||
"The provided credentials are invalid. Reason given by the server: "
|
self._send_request('guide', {})
|
||||||
+ response['error']['status'])
|
|
||||||
|
|
||||||
def _send_request(self, endpoint: str, body: Dict, additionalParams: str = "") -> Dict:
|
def _send_request(self, endpoint: str, body: Dict, additionalParams: str = "") -> Dict:
|
||||||
body.update(self.context)
|
body.update(self.context)
|
||||||
|
|
@ -109,10 +108,13 @@ class YTMusic(BrowsingMixin, WatchMixin, LibraryMixin, PlaylistsMixin, UploadsMi
|
||||||
json=body,
|
json=body,
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
proxies=self.proxies)
|
proxies=self.proxies)
|
||||||
|
response_text = json.loads(response.text)
|
||||||
if response.status_code >= 400:
|
if response.status_code >= 400:
|
||||||
raise Exception("Error: Server returned HTTP " + str(response.status_code) +
|
message = "Server returned HTTP " + str(
|
||||||
": " + response.reason + ". Please check your credentials.")
|
response.status_code) + ": " + response.reason + ".\n"
|
||||||
return json.loads(response.text)
|
error = response_text.get('error', {}).get('message')
|
||||||
|
raise Exception(message + error)
|
||||||
|
return response_text
|
||||||
|
|
||||||
def _check_auth(self):
|
def _check_auth(self):
|
||||||
if self.auth == "":
|
if self.auth == "":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue