Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Phantom-Cass opened this issue Aug 20, 2023 · 6 comments
Closed
Labels

Comments

@Phantom-Cass
Copy link

Phantom-Cass commented Aug 20, 2023

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
Copy link
Member

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

@Phantom-Cass
Copy link
Author

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

Damn, thanks for the heads-up

@aymather
Copy link

aymather commented 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.

@dieser-niko
Copy link
Member

dieser-niko commented 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: #918

@dieser-niko
Copy link
Member

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

@dieser-niko
Copy link
Member

I guess not. Closing as there is no activity.

@dieser-niko dieser-niko closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants