[GH-ISSUE #1030] Help Request from Newbie error running #615

Closed
opened 2026-02-28 00:00:17 +03:00 by kerem · 5 comments
Owner

Originally created by @tarrant33 on GitHub (Oct 4, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1030

I try running some code for a test but keep getting below errors. Im new to python and using raspberry pi

pi@raspberry:~/SpotifyTest $ python3 test1.py 
/usr/bin/xdg-open: 811: : Permission denied
^X^CTraceback (most recent call last):
  File "/home/pi/SpotifyTest/test1.py", line 34, in <module>
    current_track = sp.current_playback()
  File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 1757, in current_playback
    return self._get("me/player", market=market, additional_types=additional_types)
  File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 323, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 247, in _internal_call
    headers = self._auth_headers()
  File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 238, in _auth_headers
    token = self.auth_manager.get_access_token(as_dict=False)
  File "/home/pi/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 535, in get_access_token
    "code": code or self.get_auth_response(),
  File "/home/pi/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 490, in get_auth_response
    return self._get_auth_response_local_server(redirect_port)
  File "/home/pi/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 459, in _get_auth_response_local_server
    server.handle_request()
  File "/usr/lib/python3.9/socketserver.py", line 294, in handle_request
    ready = selector.select(timeout)
  File "/usr/lib/python3.9/selectors.py", line 416, in select
    fd_event_list = self._selector.poll(timeout)
KeyboardInterrupt

any help or insight would be greatly appreciated

Originally created by @tarrant33 on GitHub (Oct 4, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1030 I try running some code for a test but keep getting below errors. Im new to python and using raspberry pi ```bash pi@raspberry:~/SpotifyTest $ python3 test1.py /usr/bin/xdg-open: 811: : Permission denied ^X^CTraceback (most recent call last): File "/home/pi/SpotifyTest/test1.py", line 34, in <module> current_track = sp.current_playback() File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 1757, in current_playback return self._get("me/player", market=market, additional_types=additional_types) File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 323, in _get return self._internal_call("GET", url, payload, kwargs) File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 247, in _internal_call headers = self._auth_headers() File "/home/pi/.local/lib/python3.9/site-packages/spotipy/client.py", line 238, in _auth_headers token = self.auth_manager.get_access_token(as_dict=False) File "/home/pi/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 535, in get_access_token "code": code or self.get_auth_response(), File "/home/pi/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 490, in get_auth_response return self._get_auth_response_local_server(redirect_port) File "/home/pi/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 459, in _get_auth_response_local_server server.handle_request() File "/usr/lib/python3.9/socketserver.py", line 294, in handle_request ready = selector.select(timeout) File "/usr/lib/python3.9/selectors.py", line 416, in select fd_event_list = self._selector.poll(timeout) KeyboardInterrupt ``` any help or insight would be greatly appreciated
kerem 2026-02-28 00:00:17 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@dieser-niko commented on GitHub (Oct 4, 2023):

Can you post a code snippet?
And just so you know, you can use a codeblock in comments like this:

```python3
<paste in your code here>
.```

Just remove the dot at the end, that's just so I can post this with correct formatting

<!-- gh-comment-id:1747049939 --> @dieser-niko commented on GitHub (Oct 4, 2023): Can you post a code snippet? And just so you know, you can use a codeblock in comments like this: ```markdown ```python3 <paste in your code here> .``` ``` Just remove the dot at the end, that's just so I can post this with correct formatting
Author
Owner

@tarrant33 commented on GitHub (Oct 4, 2023):

import os
import time
from spotipy.oauth2 import SpotifyOAuth
from PIL import Image, ImageDraw, ImageFont
import spotipy
from rgbmatrix import RGBMatrix, RGBMatrixOptions

SPOTIPY_CLIENT_ID = 'xxx'
SPOTIPY_CLIENT_SECRET = 'xxx'
SPOTIPY_REDIRECT_URI = 'http://localhost:8080/callback'

# Initialize Spotipy with your credentials
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=os.environ['SPOTIPY_CLIENT_ID'],
                                              client_secret=os.environ['SPOTIPY_CLIENT_SECRET'],
                                              redirect_uri=os.environ['SPOTIPY_REDIRECT_URI'],
                                              scope="user-library-read user-read-currently-playing"))

# Initialize RGB matrix display with your provided options
options = RGBMatrixOptions()
options.rows = 64  # Number of rows (64 pixels)
options.cols = 64  # Number of columns (64 pixels)
options.chain_length = 2  # 2 chains
matrix = RGBMatrix(options=options)

# Set up custom font
font_directory = "fonts"
font_filename = "04B_03__.TTF"
font_path = os.path.join(font_directory, font_filename)
font = ImageFont.truetype(font_path, size=8)

while True:
    # Get currently playing track information
    current_track = sp.current_playback()
    if current_track is not None and 'item' in current_track:
        track_name = current_track['item']['name']
        album_name = current_track['item']['album']['name']
        artist_name = current_track['item']['artists'][0]['name']
        album_image_url = current_track['item']['album']['images'][0]['url']

        # Load and resize the album image
        album_image = Image.open(album_image_url)
        album_image = album_image.resize((40, 40))

        # Create a blank image for displaying information
        display = Image.new('RGB', (64, 64), color=(0, 0, 0))
        draw = ImageDraw.Draw(display)

        # Paste the resized album image on the left side
        display.paste(album_image, (0, 0))

        # Draw track name, album name, and artist name using custom font
        draw.text((45, 0), track_name, fill=(255, 255, 255), font=font)
        draw.text((45, 15), album_name, fill=(255, 255, 255), font=font)
        draw.text((45, 30), artist_name, fill=(255, 255, 255), font=font)

        # Display the information on the RGB matrix
        matrix.Clear()
        matrix.SetImage(display, 0, 0)
        time.sleep(10)  # Display the information for 10 seconds

    time.sleep(5)  # Poll for currently playing track every 5 seconds
<!-- gh-comment-id:1747112447 --> @tarrant33 commented on GitHub (Oct 4, 2023): ```python3 import os import time from spotipy.oauth2 import SpotifyOAuth from PIL import Image, ImageDraw, ImageFont import spotipy from rgbmatrix import RGBMatrix, RGBMatrixOptions SPOTIPY_CLIENT_ID = 'xxx' SPOTIPY_CLIENT_SECRET = 'xxx' SPOTIPY_REDIRECT_URI = 'http://localhost:8080/callback' # Initialize Spotipy with your credentials sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=os.environ['SPOTIPY_CLIENT_ID'], client_secret=os.environ['SPOTIPY_CLIENT_SECRET'], redirect_uri=os.environ['SPOTIPY_REDIRECT_URI'], scope="user-library-read user-read-currently-playing")) # Initialize RGB matrix display with your provided options options = RGBMatrixOptions() options.rows = 64 # Number of rows (64 pixels) options.cols = 64 # Number of columns (64 pixels) options.chain_length = 2 # 2 chains matrix = RGBMatrix(options=options) # Set up custom font font_directory = "fonts" font_filename = "04B_03__.TTF" font_path = os.path.join(font_directory, font_filename) font = ImageFont.truetype(font_path, size=8) while True: # Get currently playing track information current_track = sp.current_playback() if current_track is not None and 'item' in current_track: track_name = current_track['item']['name'] album_name = current_track['item']['album']['name'] artist_name = current_track['item']['artists'][0]['name'] album_image_url = current_track['item']['album']['images'][0]['url'] # Load and resize the album image album_image = Image.open(album_image_url) album_image = album_image.resize((40, 40)) # Create a blank image for displaying information display = Image.new('RGB', (64, 64), color=(0, 0, 0)) draw = ImageDraw.Draw(display) # Paste the resized album image on the left side display.paste(album_image, (0, 0)) # Draw track name, album name, and artist name using custom font draw.text((45, 0), track_name, fill=(255, 255, 255), font=font) draw.text((45, 15), album_name, fill=(255, 255, 255), font=font) draw.text((45, 30), artist_name, fill=(255, 255, 255), font=font) # Display the information on the RGB matrix matrix.Clear() matrix.SetImage(display, 0, 0) time.sleep(10) # Display the information for 10 seconds time.sleep(5) # Poll for currently playing track every 5 seconds ```
Author
Owner

@dieser-niko commented on GitHub (Oct 4, 2023):

Hm, can't really figure out where the "Permission denied" comes from. The other error seems to be caused by you trying to stop the script. But it would probably work with sudo.

If you want, try to debug your script and go through line by line until you get the error again.

<!-- gh-comment-id:1747789054 --> @dieser-niko commented on GitHub (Oct 4, 2023): Hm, can't really figure out where the "Permission denied" comes from. The other error seems to be caused by you trying to stop the script. But it would probably work with sudo. If you want, try to debug your script and go through line by line until you get the error again.
Author
Owner

@dieser-niko commented on GitHub (May 21, 2024):

Any updates?

<!-- gh-comment-id:2123457400 --> @dieser-niko commented on GitHub (May 21, 2024): Any updates?
Author
Owner

@dieser-niko commented on GitHub (Jun 11, 2024):

Closing as there is no activity or reply from the author.

<!-- gh-comment-id:2160337612 --> @dieser-niko commented on GitHub (Jun 11, 2024): Closing as there is no activity or reply from the author.
Sign in to join this conversation.
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/spotipy#615
No description provided.