CriticalElement / spotify-free-api-player

This allows you to modify the user's playback state through the spotify API, without needing premium.
13 stars 1 forks source link

self._authorize() timeoutError #7

Closed 44ron closed 3 months ago

44ron commented 7 months ago

Im trying to connect using a cookie string and run a skip command. examples.py:

from experimental import SpotifyPlayer
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)-8s - %(name)-14s - %(message)s')

# edge is preferred (and is now default) because reading cookies in chrome > 104.0.5112.102 needs elevation
# https://github.com/borisbabic/browser_cookie3/issues/180
spotifyplayer = SpotifyPlayer(cookie_str='my_cookie_string')
spotifyplayer.command(spotifyplayer.skip)

spotifyplayer.force_disconnect = True
spotifyplayer.disconnect()

this is my debug output:

2024-02-09 23:06:20,061 - DEBUG    - urllib3.connectionpool - Starting new HTTPS connection (1): open.spotify.com:443
2024-02-09 23:06:20,291 - DEBUG    - urllib3.connectionpool - https://open.spotify.com:443 "GET /get_access_token?reason=transport&productType=web_player HTTP/1.1" 200 239
2024-02-09 23:06:20,294 - DEBUG    - asyncio        - Using selector: KqueueSelector
2024-02-09 23:06:20,402 - DEBUG    - websockets.client - = connection is CONNECTING
Traceback (most recent call last):
  File "/Users/aaron/Desktop/spotify-free-api-player/examples.py", line 9, in <module>
    spotifyplayer = SpotifyPlayer(cookie_str='my_cookie_string')
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aaron/Desktop/spotify-free-api-player/experimental.py", line 226, in __init__
    self._authorize()
  File "/Users/aaron/Desktop/spotify-free-api-player/experimental.py", line 431, in _authorize
    raise TimeoutError
TimeoutError
CriticalElement commented 7 months ago

Does running the script without a cookie string work normally? (using the default edge login cookies)

44ron commented 7 months ago

Does running the script without a cookie string work normally? (using the default edge login cookies)

No, I'm on mac and dont use edge, I couldn't get it to work with chromium or firefox. I also tried giving cookies.sqlite path with the cookie_path parameter and that didn't work either. So i just copied the sp_t value from the .sqlite file.. Its not an expired cookie either, should work until 2024 december. Edit: As far as Ive seen it the first authorization goes through and then the timeout triggers after that.. increasing timeout to 20secs didn't help either.

CriticalElement commented 7 months ago

I'll test this further on my mac tomorrow. In the meanwhile, try logging in to spotify on an incognito tab and copying every cookie created by spotify into the cookie string, instead of just the sp_t value - maybe that would fix it?

44ron commented 5 months ago

Thank you, adding the sp_key and sp_dc cookies seems to have done the trick. But now I get a bad request error:

2024-04-04 23:23:35,535 - DEBUG - websockets.client - < TEXT '{"headers":{"Spotify-Connection-Id":"XXXXXXXXXXX"}' [526 bytes] 2024-04-04 23:23:35,773 - DEBUG - urllib3.connectionpool - Starting new HTTPS connection (1): guc-spclient.spotify.com:443 2024-04-04 23:23:35,987 - DEBUG - urllib3.connectionpool - https://guc-spclient.spotify.com:443 "POST /track-playback/v1/devices HTTP/1.1" 400 None 2024-04-04 23:23:36,017 - DEBUG - urllib3.connectionpool - Starting new HTTPS connection (1): api.spotify.com:443 2024-04-04 23:23:36,132 - DEBUG - urllib3.connectionpool - https://api.spotify.com:443 "PUT /v1/me/notifications/user?connection_id=XXXXXXXXXXXXXXXXXXXXX= HTTP/1.1" 410 0

CriticalElement commented 5 months ago

I can't replicate this, so it could be an account-related issue, so maybe try with another account I guess? Another thing that you could try is changing every request url from guc-spclient.spotify.com to guc3-spclient.spotify.com, but I don't know if this would change anything.

CriticalElement commented 3 months ago

This is pretty late, but I believe copying all of the cookies generated by Spotify should hopefully fix this error, as is what occurred when I was testing. I don't know what cookies are / are not required, but copying all/most of them should work.