Spotipy访问轨道数据不再有效

发布于 2025-02-04 09:37:12 字数 1121 浏览 1 评论 0原文

我一直在使用SpotipySpotify Web API进行AI项目。我已经收到了预览_url的列表来进行一些分析,但我已经成功地遇到了很多,但是我最近遇到了问题。每当我尝试使用.track(track_id)时,它就会卡在线上,并且不会继续越过线路。我当时认为这可能是API的问题,但是其他命令正常工作,这只是给我问题的曲目。我无法弄清楚这个问题,因为它没有给我任何错误,它只是被卡住了,试图执行该行而永远不会结束。 刷新客户秘密现在什么都没做。这是我到目前为止的代码。

from spotipy.oauth2 import SpotifyClientCredentials 
cid = '121e03d3acd1440188ae4c0f58b844d4' 
secret = '431a5e56bcd544c3aefce8166a9c3703' 
client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret) 
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

number = 2
output_file = open('data\\25k_data_preview\\track_url_preview_' + str(number) + '.txt', 'a')
for l in open('data\\25k_data\\track_url_' + str(number) + '.txt'):
    line = l.replace('\n','')
    print(line)
    try: 
        track = sp.track(line)
        try:
            testing = track['preview_url']
            if testing != None:
                output_file.write(line + " " + testing + "\n")
        except:
            x = 0
    except:
        x = 0
        
output_file.close()

I have been working on an AI project using Spotipy and the Spotify Web API. I have been getting a list of preview_url's to do some analysis on and I have successfully gotten many, but I ran into issues lately. Whenever I try to use .track(track_id) it gets stuck on the line and doesn't continue past the line. I was thinking it could be an issue with the API, but other commands work fine, it's only track that is giving me issues. I cannot figure out the issue because it doesn't give me any errors, it just gets stuck trying to execute that line and never finishes.
Refreshing the client secret does nothing now. This is the code I have so far.

from spotipy.oauth2 import SpotifyClientCredentials 
cid = '121e03d3acd1440188ae4c0f58b844d4' 
secret = '431a5e56bcd544c3aefce8166a9c3703' 
client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret) 
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

number = 2
output_file = open('data\\25k_data_preview\\track_url_preview_' + str(number) + '.txt', 'a')
for l in open('data\\25k_data\\track_url_' + str(number) + '.txt'):
    line = l.replace('\n','')
    print(line)
    try: 
        track = sp.track(line)
        try:
            testing = track['preview_url']
            if testing != None:
                output_file.write(line + " " + testing + "\n")
        except:
            x = 0
    except:
        x = 0
        
output_file.close()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文