Skip to content

About

A simple Python script to test access to the Spotify API from your VPS and log the results with detailed response information.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎧 Spotify-API-Test πŸš€

Repository Views GitHub Stars GitHub Forks GitHub Issues GitHub License

πŸ“ Overview

Spotify-API-Test is a lightweight Python utility for testing Spotify Web API authentication and connectivity from a VPS, server, or hosting environment.

It uses Spotify's Client Credentials flow to request an access token from the Spotify OAuth endpoint and reports:

  • HTTP status
  • Request duration
  • Token information (preview only)
  • Authentication errors
  • Detailed log output

The tool is useful for checking whether a server can successfully reach Spotify's authentication service and obtain an API token.

✨ Features

  • βœ… Tests Spotify OAuth token endpoint accessibility.
  • πŸ” Tests Spotify Client Credentials authentication.
  • πŸ“‘ Measures request/response time.
  • πŸ–₯️ Provides a formatted terminal interface using rich.
  • 🧾 Displays useful authentication and HTTP error information.
  • πŸ“ Saves timestamped logs inside the Log/ directory.
  • πŸ”’ Only a short token preview is displayed/logged; the full access token is not exposed.
  • 🧰 Lightweight and suitable for VPS diagnostics.
  • πŸ§‘β€πŸ’» Designed and maintained by power0matin.

πŸ›‘οΈ Requirements

  • 🐍 Python 3.7+
  • πŸ“¦ requests
  • ✨ rich for the formatted terminal UI

rich is optional at runtime because the script falls back to plain terminal output when it is unavailable.

πŸ”‘ Spotify Credentials

The script requires a Spotify Developer application and uses the following environment variables:

SPOTIFY_CLIENT_ID
SPOTIFY_CLIENT_SECRET

You can create and manage Spotify applications from the Spotify Developer Dashboard.

Set the credentials in your current shell before running the test:

export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"

⚠️ Never commit your Spotify Client Secret to Git or place it directly inside the Python source code.

To verify that both variables are set:

test -n "$SPOTIFY_CLIENT_ID" && test -n "$SPOTIFY_CLIENT_SECRET" \
  && echo "Spotify credentials are configured." \
  || echo "Spotify credentials are missing."

πŸ“₯ Installation

Ubuntu / Debian

The recommended installation method is to use a Python virtual environment.

This avoids system-wide pip restrictions on modern Debian/Ubuntu systems and keeps the project dependencies isolated.

sudo apt update
sudo apt install -y git python3 python3-venv

Clone the repository:

git clone https://github.com/power0matin/Spotify-API-Test.git
cd Spotify-API-Test

Create a virtual environment:

python3 -m venv .venv

Activate it:

source .venv/bin/activate

Install the dependencies:

python -m pip install --upgrade pip
python -m pip install requests rich

▢️ Run

First, configure your Spotify credentials:

export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"

Then run the test:

python spotify_api_test.py

The script will:

  1. Contact Spotify's OAuth token endpoint.
  2. Authenticate using Client Credentials.
  3. Measure the request duration.
  4. Report the result in the terminal.
  5. Save a detailed timestamped log in Log/.

Example:

.venv/
spotify_api_test.py
Log/
└── spotify_api_test_2026-10-05_18-30-00.log

Run Without Activating the Virtual Environment

Activation is optional. You can run the project directly through the virtual environment:

.venv/bin/python spotify_api_test.py

This is particularly convenient on VPS environments where you want a single command to execute the test.

πŸ”„ Running Again Later

After the initial installation, you only need to enter the project directory, configure the credentials if they are not already exported, and run the script:

cd ~/Spotify-API-Test

export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"

.venv/bin/python spotify_api_test.py

πŸ“ Logs

Every execution creates a timestamped log file in the Log/ directory:

Log/spotify_api_test_2026-10-05_18-30-00.log

The log contains information such as:

  • Test start time
  • Spotify token endpoint
  • Authentication result
  • HTTP status code
  • Request duration
  • Error details
  • Token preview
  • Token expiration information

πŸ–₯️ Example Output

βœ… Successful Authentication

Spotify API Connectivity Test

Status: βœ… Success
Token preview: BQC123456789...
Expires in: 3599 seconds
Request time: 0.214 seconds
Log file: Log/spotify_api_test_2026-10-05_18-30-00.log

❌ Authentication or Connectivity Error

Spotify API Connectivity Test

Status: ❌ Failed
Error: Spotify token request failed with 401: ...
Log file: Log/spotify_api_test_2026-10-05_18-31-02.log

πŸ§ͺ Troubleshooting

pip install returns externally-managed-environment

This usually means you are trying to install packages into the system Python installation on a modern Debian/Ubuntu system.

Do not install the package globally. Create and use a virtual environment instead:

sudo apt install -y python3-venv
python3 -m venv .venv
source .venv/bin/activate
python -m pip install requests rich

python: command not found

On many Ubuntu/Debian installations, the Python 3 executable is available as python3 rather than python.

After creating the virtual environment, use:

python spotify_api_test.py

or without activation:

.venv/bin/python spotify_api_test.py

SPOTIFY_CLIENT_ID or SPOTIFY_CLIENT_SECRET is not configured

Set both environment variables before running the script:

export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"

HTTP 401

A 401 response generally indicates an authentication or credential problem.

Check that:

echo "$SPOTIFY_CLIENT_ID"
echo "$SPOTIFY_CLIENT_SECRET"

contain the expected values and that you copied the credentials correctly.

HTTP 403

A 403 means the request was rejected by Spotify. Do not automatically interpret every 403 as proof that the VPS IP is blocked.

Check the response/error details in the terminal output and the corresponding log file before diagnosing the cause.

Connection or timeout errors

If the script cannot reach Spotify or the request times out, check:

curl -I https://accounts.spotify.com

You can also inspect DNS resolution:

getent hosts accounts.spotify.com

and test basic HTTPS connectivity:

curl -v https://accounts.spotify.com/api/token

πŸ“ Project Structure

Spotify-API-Test/
β”œβ”€β”€ assets/
β”œβ”€β”€ Log/
β”œβ”€β”€ spotify_api_test.py
β”œβ”€β”€ README.md
└── LICENSE

The Log/ directory is created automatically when the script runs.

🀝 Contributing

Contributions, bug reports, issues, and feature requests are welcome.

To contribute:

git checkout -b feature/your-feature
git add .
git commit -m "Add new feature"
git push origin feature/your-feature

Then open a Pull Request.

πŸ“œ License

This project is licensed under the MIT License.

πŸ“¬ Contact

Matin Shahabadi (Ω…ΨͺΫŒΩ† Ψ΄Ψ§Ω‡β€ŒΨ’Ψ¨Ψ§Ψ―ΫŒ / Ω…ΨͺΫŒΩ† Ψ΄Ψ§Ω‡ ؒبادی)

Β© Created by power0matin

About

A simple Python script to test access to the Spotify API from your VPS and log the results with detailed response information.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages