[GH-ISSUE #45] Reqquest failed, maybe Spotify no longer accepts requests in this format? #27

Closed
opened 2026-02-27 19:06:30 +03:00 by kerem · 4 comments
Owner

Originally created by @Neurologist on GitHub (Aug 18, 2025).
Original GitHub issue: https://github.com/Aran404/SpotAPI/issues/45

 BRAINS:PC via ~\Documents via 🐍 v3.12.6 🧠 v1.1 on Sun Aug 17 2025 17:38
λ python.exe control_spotify.py resume
Session loaded successfully using from_cookies method.
[17:39:52] Failed to fetch secrets: name 'response' is not defined. Falling back to default secret.
An error occurred: Could not GET https://open.spotify.com/api/token. Status Code: 400

I tried making a control script and run it, but im getting this error

Gemini says that the Api method might be outdated is this correct?

The line resp = self.client.get(...) is where your computer sends the request to Spotify's server. The server then responds with the 400 Bad Request error, which the next line catches and displays to you.

Why It Fails

The request fails because the query parameters are outdated. The library is sending a request with keys like "reason": "init" and "productType": "web-player". Spotify has updated its security and internal API, so it no longer accepts requests in this format.

....

import sys
import json # Import Python's built-in JSON library
from spotapi import Config, Login, Player, NoopLogger

# --- Configuration ---
if len(sys.argv) < 2:
    print("Error: No command provided. Use 'resume', 'pause', 'next', or 'prev'.")
    sys.exit(1)

command = sys.argv[1].lower()
session_file = "my_session.json"

# --- Main Script ---
try:
    # 1. Setup the configuration
    config = Config(logger=NoopLogger())

    # 2. Manually load the session data from the JSON file
    with open(session_file, 'r') as f:
        session_data = json.load(f)
    
    # 3. Log in using the from_cookies method, which is more direct
    login_session = Login.from_cookies(session_data, config)
    print("✅ Session loaded successfully using from_cookies method.")

    # 4. Initialize the Player
    player = Player(login_session)
    print(f"✅ Player connected. Running command: {command}")

    # 5. Execute the command
    if command == "next":
        player.skip_next()
    elif command == "prev":
        player.skip_prev()
    elif command == "pause":
        player.pause()
    elif command == "resume":
        player.resume()
    else:
        print(f"Unknown command: {command}")

    print(f"🚀 Command '{command}' executed successfully.")

except Exception as e:
    print(f"❌ An error occurred: {e}")
Originally created by @Neurologist on GitHub (Aug 18, 2025). Original GitHub issue: https://github.com/Aran404/SpotAPI/issues/45  BRAINS:PC via ~\Documents via 🐍 v3.12.6 🧠 v1.1 on Sun Aug 17 2025 17:38 λ python.exe control_spotify.py resume ✅ Session loaded successfully using from_cookies method. [17:39:52] Failed to fetch secrets: name 'response' is not defined. Falling back to default secret. ❌ An error occurred: Could not GET https://open.spotify.com/api/token. Status Code: 400 I tried making a control script and run it, but im getting this error Gemini says that the Api method might be outdated is this correct? The line resp = self.client.get(...) is where your computer sends the request to Spotify's server. The server then responds with the 400 Bad Request error, which the next line catches and displays to you. Why It Fails The request fails because the query parameters are outdated. The library is sending a request with keys like "reason": "init" and "productType": "web-player". Spotify has updated its security and internal API, so it no longer accepts requests in this format. .... ``` import sys import json # Import Python's built-in JSON library from spotapi import Config, Login, Player, NoopLogger # --- Configuration --- if len(sys.argv) < 2: print("Error: No command provided. Use 'resume', 'pause', 'next', or 'prev'.") sys.exit(1) command = sys.argv[1].lower() session_file = "my_session.json" # --- Main Script --- try: # 1. Setup the configuration config = Config(logger=NoopLogger()) # 2. Manually load the session data from the JSON file with open(session_file, 'r') as f: session_data = json.load(f) # 3. Log in using the from_cookies method, which is more direct login_session = Login.from_cookies(session_data, config) print("✅ Session loaded successfully using from_cookies method.") # 4. Initialize the Player player = Player(login_session) print(f"✅ Player connected. Running command: {command}") # 5. Execute the command if command == "next": player.skip_next() elif command == "prev": player.skip_prev() elif command == "pause": player.pause() elif command == "resume": player.resume() else: print(f"Unknown command: {command}") print(f"🚀 Command '{command}' executed successfully.") except Exception as e: print(f"❌ An error occurred: {e}") ```
kerem closed this issue 2026-02-27 19:06:30 +03:00
Author
Owner

@Neurologist commented on GitHub (Aug 18, 2025):

Can you delete this issue please?!

<!-- gh-comment-id:3194871489 --> @Neurologist commented on GitHub (Aug 18, 2025): Can you delete this issue please?!
Author
Owner

@gewinnorientiert commented on GitHub (Aug 19, 2025):

How did you fix it?

<!-- gh-comment-id:3202124531 --> @gewinnorientiert commented on GitHub (Aug 19, 2025): How did you fix it?
Author
Owner

@gewinnorientiert commented on GitHub (Aug 19, 2025):

The TOTP Version changed to 32 and there is a new totp secret most likely. Would need help with that.

<!-- gh-comment-id:3202154904 --> @gewinnorientiert commented on GitHub (Aug 19, 2025): The TOTP Version changed to 32 and there is a new totp secret most likely. Would need help with that.
Author
Owner

@Neurologist commented on GitHub (Aug 21, 2025):

I used an AHK (autohotkey) script instead, it's much better, requires no dependencies and i can use it on my stream deck..
spotify_play_pause.ahk

ControlSend, , "{Media_Play_Pause}", ahk_exe Spotify.exe

OP, please delete this thread,, no longer needed and don't want it showing on my profile !

<!-- gh-comment-id:3209612257 --> @Neurologist commented on GitHub (Aug 21, 2025): I used an AHK (autohotkey) script instead, it's much better, requires no dependencies and i can use it on my stream deck.. spotify_play_pause.ahk ``` ControlSend, , "{Media_Play_Pause}", ahk_exe Spotify.exe ``` OP, please delete this thread,, no longer needed and don't want it showing on my profile !
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SpotAPI#27
No description provided.