From 8840adcd874cb0d39da24efd29252c49780ddf71 Mon Sep 17 00:00:00 2001 From: Benjamin Ye Date: Mon, 3 Jun 2024 14:14:02 -0700 Subject: [PATCH] Fix Playwright exception; resolves #16 --- src/minim/spotify.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/minim/spotify.py b/src/minim/spotify.py index 6a1b940..79c724c 100644 --- a/src/minim/spotify.py +++ b/src/minim/spotify.py @@ -773,8 +773,10 @@ def _get_authorization_code(self, code_challenge: str = None) -> str: context = browser.new_context(record_har_path=har_file) page = context.new_page() page.goto(auth_url, timeout=0) - page.wait_for_url(f"{self._redirect_uri}*", - wait_until="commit") + with page.expect_request( + "https://accounts.spotify.com/*/authorize/accept*" + ) as _: + pass # blocking call context.close() browser.close() @@ -782,7 +784,7 @@ def _get_authorization_code(self, code_challenge: str = None) -> str: queries = dict( urllib.parse.parse_qsl( urllib.parse.urlparse( - re.search(f'{self._redirect_uri}\?(.*?)"', + re.search(fr'{self._redirect_uri}\?(.*?)"', f.read()).group(0) ).query ) @@ -1150,7 +1152,7 @@ def set_flow( if redirect_uri: self._redirect_uri = redirect_uri if "localhost" in redirect_uri: - self._port = re.search("localhost:(\d+)", + self._port = re.search(r"localhost:(\d+)", redirect_uri).group(1) elif web_framework: wmsg = ("The redirect URI is not on localhost, "