-
Notifications
You must be signed in to change notification settings - Fork 953
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
warning:couldn't write token cache to .cache-xxxxxxxxxx #363
Comments
Hello, i can't go furether because my token can't go to the cache. Is someone have a solution ... |
Did you ever figure this out? I get: and a link to a page that states: I have read that a lot of people were having trouble with the token part but I double checked and it seems right: 'token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) |
I may have a solution. Problem:On Windows 10, Windows Defender tends to block new programs from writing to personal C:/ areas (Documents, Pictures, etc...) with "Ransomware protection" and with proper error catching, would normally say the file/folder doesn't exist. Solution:What I did was:
Assuming you're the administrator:
Hope that helps :) |
@HurleybirdJr nice, we can add that to the FAQ |
I am having a similar problem myself. I am trying to run my .py script with a batch file on my Windows command line. After it authorizes my Spotify and I enter the URl I was directed to, I get this output: I checked my ransomware on the 3rd party security I use and python.exe is an allowed program. |
@jane-dempsey is the same happening if you try to run the python file directly, without the help of a batch file? Perhaps, the batch file doesn't have sufficient authorization and would need to be added to the list of allowed programs, or it should be ran as an administrator |
@stephanebruckert I tried the following:
If it is useful, here is my intial start-up code:
It's at this point the .py and .bat files open up a new tab in Google Chrome and I do the same routine and pasting the URL into the command line. After that is when the command line either closes spontaneously or I get the above message I mentioned. |
Also try to run your command line (cmd.exe?) as administrator. I don't know why Windows would need this but I'm hoping to unblock you at the moment. And, have to say it's really weird that it only happens with specific scopes... |
@stephanebruckert I tried running my cmd line as admin, as well as my .bat file and Python 3.8. Same error. I figured it out! It was a line in my code :) Thank you!! |
What was it exactly? Please share all details as it will definitely be useful for others! |
Sure did two things, so for future references users can try both:
|
I have found a working solution! The problem is that spotipy tries to create a file named".cache-USERNAME". |
I think there can be several reasons for not being able to write to this file; letting pythonw through Defender seems terribly insecure. As I understand it windows doesn't "like" dotfiles. Somehow or another my .cache file had the Hidden attribute set. I'm pretty sure because I'm using git (ya, that cache file shouldn't be put in the git repository!) When I changed its attribute the program then worked. (https://stackoverflow.com/questions/2118606/why-do-i-get-a-windows-file-permission-error-io-error-13-with-android-sdk-when) There are ways to work around this by the user; but I suggest that spotify should recognize it is working on Windows and set attributes appropriately. The workaround (for me) was to initialize the Auth manager with a non-dotfile cache name:
I was able to change the hidden attribute of the .cache file and have it run, but seems clear this will be a problem soon enough in the future. When looking at the code for CacheFileHandler I saw some unpythonic and potentially erroneous code. It uses the form:
If you get an exception on the read/write the file handle will never be closed. The following is preferred as it ensures the file handle is closed even if there is an exception:
|
This is interesting. If you all Windows users think we should rename these cache files to not start with a dot, let's do it! It might be a backward-incompatible change, but we are preparing a V3 for this #652 |
No description provided.
The text was updated successfully, but these errors were encountered: