Skip to content

Commit

Permalink
Fix Playwright exception; resolves #16
Browse files Browse the repository at this point in the history
  • Loading branch information
bbye98 committed Jun 3, 2024
1 parent 7a6fa5c commit 8840adc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/minim/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,16 +773,18 @@ 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()

with open(har_file, "r") as f:
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
)
Expand Down Expand Up @@ -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, "
Expand Down

0 comments on commit 8840adc

Please sign in to comment.