What I’m trying to do:
What I’m trying to do is create a sort of custom control for Spotify for a fun project. I am using Spotipy for this. What I’ve tried and what’s not working:
Iemphasized text set it up to where you click pause, and once you do that it calls to the server to communicate with Spotify
what happens the the server just gives me an anvil.server.timeouterror: server took to long to respond. When I run this code is a normal code editor it works just fine and I have spent trying to find a solution but with no luck. I am very new to using anvil and apologize if this is an easy fix. Thank you for your help in advance
I am unfamiliar with spotipy however, if my code worked on my local machine, but not in the anvil server module run in the cloud, this is the first thing that would stick out to me as needing to be addressed:
This would allow you to connect to your own computer, however there is no “local” computer you are connecting to when you are running in the cloud.
I just looked into it for you, you need the OAUTH token that it asked you for the first time you ran it on your local computer.
So when you ran the python script the first time, it probably asked you for something like “go to this link, or click here to a web page and sign in and then paste the link it redirects you to here”
When you pasted in the link it made a temporary token that gives the app the ability to control your spotify, since the anvil app has no idea who you are it can’t control your spotify without that token (Usually a file).
What’s happening is that it is trying to open a python input() call for you to paste in the token information after logging in to spotify, but anvil has no terminal so you get an error because there’s no way for you to copy or paste anything into some text based anvil console somewhere when you do a server call from the client.
(This is 99% of the time what an EOF error is, that the console is waiting for input and its also impossible for it to get any, so the python interpreter just stops reading the rest of the code)
It might be possible to move your token file or string from your local pc to the anvil server module, but from what I read your token is only good for about 1hr, and also anyone you has your anvil app will be able to control only your spotify, and not the spotify of any body else.
In the long term if you want the app to be usable by other people, you can dig into the code and find that link to generate the token.
You could then have a workflow for your users where they click the link and navigate to that part and (hopefully without any CORS issues) get the token that they can store for their session to control their spotify by passing it from the client to the server module when they try to do things on the client page.