[GH-ISSUE #1019] TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union #605

Closed
opened 2026-02-28 00:00:11 +03:00 by kerem · 6 comments
Owner

Originally created by @Phantom-Cass on GitHub (Aug 20, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1019

import spotipy
import xlsxwriter
import requests
from youtubesearchpython import VideosSearch
from pytube import YouTube
import os
import moviepy.editor as mpy
from moviepy.video.tools.segmenting import findObjects
from pprint import pprint

# Spotify app credentials.
client_id = ""
client_secret = ""
def Download(link):
    yt = YouTube(link)
    video = yt.streams.filter(only_audio=True).first()
    destination = "YT Downloads"
    out_file = video.download(output_path=destination)
  
    base, ext = os.path.splitext(out_file)
    new_file = base + '.mp3'
    os.rename(out_file, new_file)


# Spotify authorization URL.
auth_url = "https://accounts.spotify.com/api/token"

# Request access token.
r = requests.post(auth_url,
                  data={"grant_type": "client_credentials",
                       "client_id": client_id,
                       "client_secret": client_secret})

# Check if the request was successful.
if r.status_code == 200:
    # Get the access token.
    token = r.json()["access_token"]
    print(token)
else:
    print("Error getting access token.")

# Create a Spotify object
spotify = spotipy.Spotify(auth=token)

# Get the list of worldwide top hits.
keywords = []
excel_crap=[]
top_tracks = spotify.playlist_items("37i9dQZEVXbMDoHDwVN2tF")
#pprint(top_tracks["items"])
for i in range(0,25):
    j = top_tracks["items"][i]
    name = j["track"]["name"]
    musician= j["track"]["artists"][0]["name"]
    duration = j["track"]["duration_ms"]
    keywords.append (f"{name} - {musician}")
    excel_crap.append([{"title":name,"artist":musician, "duration":duration}])

workbook = xlsxwriter.Workbook('global hits.xlsx')
 
# The workbook object is then used to add new worksheet via the add_worksheet() method.
worksheet = workbook.add_worksheet()
 
# Use the worksheet object to write data via the write() method.
worksheet.write('A1', 'Title')
worksheet.write('B1', 'Artist')
worksheet.write('C1', 'Duration')

for i in range(1,26):
    worksheet.write(f'A{i}', excel_crap[i-2][0]['title'])
    worksheet.write(f'B{i}', excel_crap[i-2][0]['artist'])
    worksheet.write(f'C{i}', excel_crap[i-2][0]['duration'])
workbook.close()

This code raises the TypeError mentionned above. I'm not sure if it is my fault or not, I've unlikely overwritten a built-in feature. Here's the full exception message:

Exception ignored in: <function Spotify.del at 0x000001A55C03F060>
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\spotipy\client.py", line 214, in del
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

What I attempted:

Changing Spotipy versions (2.22.0)
Checking requests.session (returned None)

Originally created by @Phantom-Cass on GitHub (Aug 20, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1019 ```python3 import spotipy import xlsxwriter import requests from youtubesearchpython import VideosSearch from pytube import YouTube import os import moviepy.editor as mpy from moviepy.video.tools.segmenting import findObjects from pprint import pprint # Spotify app credentials. client_id = "" client_secret = "" def Download(link): yt = YouTube(link) video = yt.streams.filter(only_audio=True).first() destination = "YT Downloads" out_file = video.download(output_path=destination) base, ext = os.path.splitext(out_file) new_file = base + '.mp3' os.rename(out_file, new_file) # Spotify authorization URL. auth_url = "https://accounts.spotify.com/api/token" # Request access token. r = requests.post(auth_url, data={"grant_type": "client_credentials", "client_id": client_id, "client_secret": client_secret}) # Check if the request was successful. if r.status_code == 200: # Get the access token. token = r.json()["access_token"] print(token) else: print("Error getting access token.") # Create a Spotify object spotify = spotipy.Spotify(auth=token) # Get the list of worldwide top hits. keywords = [] excel_crap=[] top_tracks = spotify.playlist_items("37i9dQZEVXbMDoHDwVN2tF") #pprint(top_tracks["items"]) for i in range(0,25): j = top_tracks["items"][i] name = j["track"]["name"] musician= j["track"]["artists"][0]["name"] duration = j["track"]["duration_ms"] keywords.append (f"{name} - {musician}") excel_crap.append([{"title":name,"artist":musician, "duration":duration}]) workbook = xlsxwriter.Workbook('global hits.xlsx') # The workbook object is then used to add new worksheet via the add_worksheet() method. worksheet = workbook.add_worksheet() # Use the worksheet object to write data via the write() method. worksheet.write('A1', 'Title') worksheet.write('B1', 'Artist') worksheet.write('C1', 'Duration') for i in range(1,26): worksheet.write(f'A{i}', excel_crap[i-2][0]['title']) worksheet.write(f'B{i}', excel_crap[i-2][0]['artist']) worksheet.write(f'C{i}', excel_crap[i-2][0]['duration']) workbook.close() ``` This code raises the TypeError mentionned above. I'm not sure if it is my fault or not, I've unlikely overwritten a built-in feature. Here's the full exception message: > Exception ignored in: <function Spotify.__del__ at 0x000001A55C03F060> Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\spotipy\client.py", line 214, in __del__ TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union What I attempted: Changing Spotipy versions (2.22.0) Checking requests.session (returned None)
kerem 2026-02-28 00:00:11 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@dieser-niko commented on GitHub (Aug 21, 2023):

WARNING! Delete/Reset your application right away!! Your client ID and secret are in this comment.

<!-- gh-comment-id:1685799157 --> @dieser-niko commented on GitHub (Aug 21, 2023): WARNING! Delete/Reset your application right away!! Your client ID and secret are in this comment.
Author
Owner

@Phantom-Cass commented on GitHub (Aug 21, 2023):

WARNING! Delete/Reset your application right away!! Your client ID and secret are in this comment.

Damn, thanks for the heads-up

<!-- gh-comment-id:1686079890 --> @Phantom-Cass commented on GitHub (Aug 21, 2023): > WARNING! Delete/Reset your application right away!! Your client ID and secret are in this comment. Damn, thanks for the heads-up
Author
Owner

@aymather commented on GitHub (Mar 5, 2024):

Did we ever figure out why this is happening/what to do? I hate seeing this in the logs every time i run a script.

<!-- gh-comment-id:1979795228 --> @aymather commented on GitHub (Mar 5, 2024): Did we ever figure out why this is happening/what to do? I hate seeing this in the logs every time i run a script.
Author
Owner

@dieser-niko commented on GitHub (Mar 6, 2024):

Tbh I didn't really read the issue because of the formatting. But I've seen this error before in another issue. Are you using conda by any chance?

Edit: found the (still open) issue: https://github.com/spotipy-dev/spotipy/issues/918

<!-- gh-comment-id:1980234301 --> @dieser-niko commented on GitHub (Mar 6, 2024): Tbh I didn't really read the issue because of the formatting. But I've seen this error before in another issue. Are you using conda by any chance? Edit: found the (still open) issue: https://github.com/spotipy-dev/spotipy/issues/918
Author
Owner

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

@Phantom-Cass @aymather is this bug still happening? I'd like to get it sorted out.

<!-- gh-comment-id:2089235043 --> @dieser-niko commented on GitHub (May 1, 2024): @Phantom-Cass @aymather is this bug still happening? I'd like to get it sorted out.
Author
Owner

@dieser-niko commented on GitHub (Jul 10, 2024):

I guess not. Closing as there is no activity.

<!-- gh-comment-id:2220348084 --> @dieser-niko commented on GitHub (Jul 10, 2024): I guess not. Closing as there is no activity.
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#605
No description provided.