spotipy-dev / spotipy

A light weight Python library for the Spotify Web API
http://spotipy.readthedocs.org
MIT License
5.03k stars 957 forks source link

TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union #1019

Closed Phantom-Cass closed 4 months ago

Phantom-Cass commented 1 year ago
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)

dieser-niko commented 1 year ago

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

Phantom-Cass commented 1 year ago

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

Damn, thanks for the heads-up

aymather commented 8 months ago

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.

dieser-niko commented 8 months ago

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

dieser-niko commented 6 months ago

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

dieser-niko commented 4 months ago

I guess not. Closing as there is no activity.