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.
- β 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.
- π Python 3.7+
- π¦
requests - β¨
richfor the formatted terminal UI
rich is optional at runtime because the script falls back to plain terminal output when it is unavailable.
The script requires a Spotify Developer application and uses the following environment variables:
SPOTIFY_CLIENT_ID
SPOTIFY_CLIENT_SECRETYou 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."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-venvClone the repository:
git clone https://github.com/power0matin/Spotify-API-Test.git
cd Spotify-API-TestCreate a virtual environment:
python3 -m venv .venvActivate it:
source .venv/bin/activateInstall the dependencies:
python -m pip install --upgrade pip
python -m pip install requests richFirst, 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.pyThe script will:
- Contact Spotify's OAuth token endpoint.
- Authenticate using Client Credentials.
- Measure the request duration.
- Report the result in the terminal.
- Save a detailed timestamped log in
Log/.
Example:
.venv/
spotify_api_test.py
Log/
βββ spotify_api_test_2026-10-05_18-30-00.log
Activation is optional. You can run the project directly through the virtual environment:
.venv/bin/python spotify_api_test.pyThis is particularly convenient on VPS environments where you want a single command to execute the test.
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.pyEvery 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
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
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
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 richOn 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.pyor without activation:
.venv/bin/python spotify_api_test.pySet both environment variables before running the script:
export SPOTIFY_CLIENT_ID="your_client_id"
export SPOTIFY_CLIENT_SECRET="your_client_secret"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.
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.
If the script cannot reach Spotify or the request times out, check:
curl -I https://accounts.spotify.comYou can also inspect DNS resolution:
getent hosts accounts.spotify.comand test basic HTTPS connectivity:
curl -v https://accounts.spotify.com/api/tokenSpotify-API-Test/
βββ assets/
βββ Log/
βββ spotify_api_test.py
βββ README.md
βββ LICENSE
The Log/ directory is created automatically when the script runs.
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-featureThen open a Pull Request.
This project is licensed under the MIT License.
Matin Shahabadi (Ω ΨͺΫΩ Ψ΄Ψ§ΩβΨ’Ψ¨Ψ§Ψ―Ϋ / Ω ΨͺΫΩ Ψ΄Ψ§Ω Ψ’Ψ¨Ψ§Ψ―Ϋ)
- Website: matinshahabadi.ir
- Email: me@matinshahabadi.ir
- GitHub: power0matin
- LinkedIn: matin-shahabadi
Β© Created by power0matin