[Python] Setting up spotipy in pythonanywhere

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm making a program which I want to run continuously hence the python anywhere. The prgram worked when it was on my local device

    def setup():
    spOauth = SpotifyOAuth(client_id=CLIENTID,
    client_secret=CLIENTSECRET,
    redirect_uri=REDIRECTURI,
    scope=SCOPE,
    show_dialog=True)

    return Spotify(auth_manager = spOauth)



    def main():

    anon = "insert anon here"
    url = "insert supabase url here"

    supabase: Client = create_client(url,anon) #set up the connection to the database

    sp = setup() #set up the connection to spotipy

    refreshRate = 30

    current = {"length": 120000} #default used for if no song is being listened to
    run = True
    count = -1

    while run:

    nowp = getCurrentSong(sp)
    if nowp == 0:
    sp = setup()

    else:
    if nowp != current:
    if count >=current["length"]/2000: #if youve listened to half the song add
    SQLappend(current,supabase)

    if nowp!=-1: #if there is a new song
    current = nowp #update current
    refreshRate = current["length"]/4000 # and refreshrate

    else:
    current = {"length": 120000} # if the music has stopped go back to default
    refreshRate = current["length"]/4000


    count = 0 #reset timer


    elif nowp != -1: #if there is music
    count = count+refreshRate #keep track of for how long

    time.sleep(refreshRate)#wait some amount of time



    this works perfectly on my local device but when I upload it to pythonanywhere after I've chaged the redirect URL it doesnt work.

    I know the error must be in the set up because when I hard code in the tokens it works until they expire

    I have no clue where to go from here any help would be appreciated even a nudge in some direction

    Continue reading...

Compartilhe esta Página