mirror of
https://github.com/beetbox/beets.git
synced 2026-03-27 07:43:38 +01:00
Bound Spotify auth retry during search
Replace recursive 401 handling with a single retry loop. This prevents unbounded recursion when authentication keeps failing.
This commit is contained in:
parent
9b63985989
commit
9855d46901
1 changed files with 26 additions and 19 deletions
|
|
@ -27,6 +27,7 @@ import re
|
|||
import threading
|
||||
import time
|
||||
import webbrowser
|
||||
from http import HTTPStatus
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Literal
|
||||
|
||||
import confuse
|
||||
|
|
@ -477,27 +478,33 @@ class SpotifyPlugin(
|
|||
:param filters: Field filters to apply.
|
||||
:param query_string: Additional query to include in the search.
|
||||
"""
|
||||
response = requests.get(
|
||||
self.search_url,
|
||||
headers={"Authorization": f"Bearer {self.access_token}"},
|
||||
params={
|
||||
**params.filters,
|
||||
"q": params.query,
|
||||
"type": params.query_type,
|
||||
"limit": str(params.limit),
|
||||
},
|
||||
timeout=10,
|
||||
)
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.HTTPError:
|
||||
if response.status_code == 401:
|
||||
self._authenticate()
|
||||
return self.get_search_response(params)
|
||||
for _ in range(2):
|
||||
response = requests.get(
|
||||
self.search_url,
|
||||
headers={"Authorization": f"Bearer {self.access_token}"},
|
||||
params={
|
||||
**params.filters,
|
||||
"q": params.query,
|
||||
"type": params.query_type,
|
||||
"limit": str(params.limit),
|
||||
},
|
||||
timeout=10,
|
||||
)
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.HTTPError:
|
||||
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
||||
self._authenticate()
|
||||
continue
|
||||
raise
|
||||
|
||||
raise
|
||||
return (
|
||||
response.json()
|
||||
.get(f"{params.query_type}s", {})
|
||||
.get("items", [])
|
||||
)
|
||||
|
||||
return response.json().get(f"{params.query_type}s", {}).get("items", [])
|
||||
return ()
|
||||
|
||||
def commands(self) -> list[ui.Subcommand]:
|
||||
# autotagger import command
|
||||
|
|
|
|||
Loading…
Reference in a new issue