Add more detail to 4xx error messages

This commit is contained in:
sigma67 2021-01-11 11:10:09 +01:00
commit 8a87dfc65f
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0

View file

@ -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 == "":