blastbeng / spotisub

Spotify to subsonic Playlist Generator and Importer
MIT License
105 stars 6 forks source link

Error connecting to spotify #33

Closed gardiol closed 2 months ago

gardiol commented 2 months ago

I created the Spotify app, configured the env variables:

      - SPOTIPY_CLIENT_ID=xxx
      - SPOTIPY_CLIENT_SECRET=yyy
      - SPOTIPY_REDIRECT_URI=http://127.0.0.1:8080/

I have run the ./first_run.sh script, copied the URL to the browser, and copied back the entire response URL (which was an invalid 127.0.0.1:8080 URL, of course), the ./cache/spotipy_cache has been created:

{"access_token": "xxx-xxx-xxx", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "xxx-xxx-xxx", "scope": "user-library-read user-read-recently-played user-top-read", "expires_at": 1726649278}

This is the error that i get:

2024-09-18 09:48:49 ERROR    HTTP Error for GET to https://api.spotify.com/v1/recommendations with Params: {'limit': 1000, 'seed_artists': 'xxx'} returned 400 due to invalid request
Exception in thread Thread-2 (<lambda>):
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 275, in _internal_call
    response.raise_for_status()
  File "/home/user/.local/lib/python3.10/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?limit=1000&seed_artists=xxx

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/spotisub/./main.py", line 93, in <lambda>
    threading.Thread(target=lambda: generate_playlists.all_artists_recommendations()).start()
  File "/home/user/spotisub/./spotisub/helpers/generate_playlists.py", line 145, in all_artists_recommendations
    show_recommendations_for_artist(artist_name)
  File "/home/user/spotisub/./spotisub/helpers/generate_playlists.py", line 92, in show_recommendations_for_artist
    results = sp.recommendations(seed_artists=[artist['id']], limit=int(os.environ.get(constants.ITEMS_PER_PLAYLIST, constants.ITEMS_PER_PLAYLIST_DEFAULT_VALUE)))
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 1728, in recommendations
    return self._get("recommendations", **params)
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 327, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 297, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?limit=1000&seed_artists=xxx:
 invalid request, reason: None

(of course i replace all sensitive parts with xxx)

blastbeng commented 2 months ago

I created the Spotify app, configured the env variables:

      - SPOTIPY_CLIENT_ID=xxx
      - SPOTIPY_CLIENT_SECRET=yyy
      - SPOTIPY_REDIRECT_URI=http://127.0.0.1:8080/

I have run the ./first_run.sh script, copied the URL to the browser, and copied back the entire response URL (which was an invalid 127.0.0.1:8080 URL, of course), the ./cache/spotipy_cache has been created:

{"access_token": "xxx-xxx-xxx", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "xxx-xxx-xxx", "scope": "user-library-read user-read-recently-played user-top-read", "expires_at": 1726649278}

This is the error that i get:

2024-09-18 09:48:49 ERROR    HTTP Error for GET to https://api.spotify.com/v1/recommendations with Params: {'limit': 1000, 'seed_artists': 'xxx'} returned 400 due to invalid request
Exception in thread Thread-2 (<lambda>):
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 275, in _internal_call
    response.raise_for_status()
  File "/home/user/.local/lib/python3.10/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?limit=1000&seed_artists=xxx

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/spotisub/./main.py", line 93, in <lambda>
    threading.Thread(target=lambda: generate_playlists.all_artists_recommendations()).start()
  File "/home/user/spotisub/./spotisub/helpers/generate_playlists.py", line 145, in all_artists_recommendations
    show_recommendations_for_artist(artist_name)
  File "/home/user/spotisub/./spotisub/helpers/generate_playlists.py", line 92, in show_recommendations_for_artist
    results = sp.recommendations(seed_artists=[artist['id']], limit=int(os.environ.get(constants.ITEMS_PER_PLAYLIST, constants.ITEMS_PER_PLAYLIST_DEFAULT_VALUE)))
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 1728, in recommendations
    return self._get("recommendations", **params)
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 327, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/home/user/.local/lib/python3.10/site-packages/spotipy/client.py", line 297, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?limit=1000&seed_artists=xxx:
 invalid request, reason: None

(of course i replace all sensitive parts with xxx)

I had similar errors once, and it was because i was hitting Spotify rate limit Also, can you try to ping "api.spotify.com" ?

EDIT: also make sure your docker network can reach the spotify APIs endpoint

gardiol commented 2 months ago

I will need to try again. Do i need to add a user to my app for it to work? i mean in the spotify dev console

blastbeng commented 2 months ago

I will need to try again. Do i need to add a user to my app for it to work? i mean in the spotify dev console

No, you just need to add the correct redirect Uri

If I remember correctly, I haven't added anything in my app except for the redirect uri

blastbeng commented 2 months ago

Closing as this issues seems not related to Spotisub