mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #644] recommendations() requests.exceptions.HTTPError #382
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#382
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @carolynzech on GitHub (Feb 20, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/644
I have the following code:
and I am getting the following errors:
Any help would be much appreciated!
@Peter-Schorn commented on GitHub (Feb 20, 2021):
The total number of seed genres, seed artists, and seed tracks must add up to five or less. See https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-recommendations
@Peter-Schorn commented on GitHub (Feb 20, 2021):
There's also a pretty simple way to debug error you're getting in the
SpotifyAuthBase.__del__. The second argument passed toisinstance()isrequests.Session, which is a type. More specifically, it's a class. The fact that the error message suggests that it's not a type means that this name is somehow being reassigned to some other object that's not a type. Change the__del__method as follows to find out what this name is being reassigned to (and what its type is):@carolynzech commented on GitHub (Feb 21, 2021):
Your comments fixed both of my issues. Thank you for your timely and detailed response--I really appreciate it.
@Peter-Schorn commented on GitHub (Feb 21, 2021):
I'm still curious about the cause of the error in the
__del__method. In theory, this should be unrelated to the issue with the recommendations endpoint. This error has come up in multiple issues, yet I've been unable to reproduce it. Can you try to reproduce it with the modified__del__method that I posted?@carolynzech commented on GitHub (Feb 22, 2021):
I also was unable to reproduce it. I wasn't able to figure out how to get around read-only permissions (I installed with pip) in PyCharm, and when I pulled directly from this repo instead, I couldn't compile the code because of a ModuleNotFound error for the cache_handler file, even though the module was clearly there. Instead, I took the code you wrote and replaced self._session with sp. When I ran the try-except at the top of the file, it didn't work, but when I instantiated the sp object inside my main method and ran the try-except there, the error went away. This isn't ideal, since now I have to pass the sp variable into every one of my functions, but it's not too big of a deal. For clarification, I had this:
and now I have this:
which works fine. If you know how to get around the read-only permissions in PyCharm, I'd be happy to try to reproduce it with the
__del__method you wrote. I did some research to no avail--it prompts me to change the read-only permissions, only to tell me each time that it was unable to execute that request.@Peter-Schorn commented on GitHub (Feb 22, 2021):
What operating system are you using?
@Peter-Schorn commented on GitHub (Feb 22, 2021):
For Linux/macOS navigate to the root directory of the spotipy library and run:
For windows, see here: https://stackoverflow.com/a/25119398/12394554
@Peter-Schorn commented on GitHub (Feb 22, 2021):
What did you mean when you said that you "replaced self._session with sp"? If you're having trouble reproducing the error, then make sure you change as little as possible. Only change the
__del__method as I described above. Make the same exact call to the recommendations endpoint that you did in the original code (i.e., with the incorrect number of seed tracks/artists).@carolynzech commented on GitHub (Feb 22, 2021):
Okay, the sudo command worked. I ran the
__del__method you wrote with the same call to recommendations as in the original post (the incorrect one), and got this:In case it helps, this error also comes up whether I call recommendations() or not. If I change the main() method to do nothing at all (just pass), it still prints:
since I'm still instantiating sp at the top of the file. The difference comes from whether sp is instantiated at the top of the file, or inside the main method. If it's inside the main method, there's no error, and if it's outside, there's this error.
@Peter-Schorn commented on GitHub (Feb 22, 2021):
At the beginning of your code, import requests and
print(requests.Session). See if it'sNone.@Peter-Schorn commented on GitHub (Feb 22, 2021):
@stephanebruckert Any idea why
requests.Sessionwould beNone?@carolynzech commented on GitHub (Feb 23, 2021):
returns
@Findus23 commented on GitHub (May 14, 2021):
Just FYI: I have the same issue and absolutely no clue what is going wrong. I updated a lot of dependencies in my application (including requests and spotipy from 2.16.1 to 2.18.0, but quickly downgrading both doesn't seem to fix it) and since then I get the mentioned exception on every run (both in oauth2.py and in client.py).
type(requests.Session)prints<class 'NoneType'>I updated the code to
which of course isn't a solution (as it probably breaks the Session), but as my script is not running permanently, but as a scheduled task with very few requests per run, I doubt it will hurt that much.
@Peter-Schorn commented on GitHub (May 14, 2021):
@Findus23 What do you mean by "breaks the Session"?
@Findus23 commented on GitHub (May 14, 2021):
Sorry for being vague: I mean by that this change might mean that requests use it's Session class anymore as it is not properly closed and therfore a new TCP connection is opened for every request instead of reusing them.
But this is just a blind guess.
@Peter-Schorn commented on GitHub (May 14, 2021):
Why don't you just catch the error as I did here? Using
if requests.Sessionis a terrible idea because who knows what the__bool__method will return. If you're trying to check if it's notNone, then do so explicitly:if requests.Session is not None.If
requests.Sessionhas somehow been assigned toNone(which is what causes this exception), thenself._sessionwon't be properly closed regardless of whether you use your updated version of__del__or the current version.The only way to ensure that the session is properly closed in the
__del__method is to find the underlying reason thatrequests.Sessionis being assigned toNone.@Findus23 commented on GitHub (Nov 25, 2021):
Once again I tried to find out what causes this and by simplifying my code step by step, I found out that adding a
from flask import Flask/import flaskin the same file as spotipy causes this issue (even if Flask is never used in any way).So this minimal example breaks for me both during development and on the main server:
I am using flask 2.0.2 and have absolutely no clue why this would happen.
@dieser-niko commented on GitHub (Aug 28, 2024):
@Findus23 is this still an issue? Because even after downgrading I can't reproduce this error.
@Findus23 commented on GitHub (Aug 28, 2024):
@dieser-niko Good question. I checked again and it seems like I have been including the workaround of modifying del ever since. But I just tested removing it and it still seems to work, so I guess maybe some flask update fixed it?
Either way I also can't reproduce it anymore.
@dieser-niko commented on GitHub (Aug 28, 2024):
The thing is, I've seen this error multiple times in other issues but was never able to reproduce it myself. Kind of frustrating.
Popped up on stackoverflow as well: https://stackoverflow.com/questions/78871882/spotipy-has-started-printing-warning-of-a-typeerror-when-calling-isinstanceself
@dieser-niko commented on GitHub (Mar 3, 2025):
Closing in favour of #621 as it seems to be related