[GH-ISSUE #768] Can't search for artist and year at the same time #467

Closed
opened 2026-02-27 23:22:48 +03:00 by kerem · 2 comments
Owner

Originally created by @Zacharias3D on GitHub (Jan 10, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/768

Hi everyone,

I am trying to use the search-function to query for a specific song from a specific year.
To accomplish this I call the search-function with q=track:Chattanooga Choo Choo+year:1939. This works just fine when trying the request in postman, but when executing it in Python I do not get any results.

When I debugged, I realized that in the _encode_params()-function of the models-module in requests-lib, my query string is encoded which leads to the replacement of the joining "+" in my query-string ("+" becomes "%2B"). It seems though, that the Spotify API needs a "+" and not a URI-encoded "+".
When trying the query-string track:Chattanooga%20Choo%20Choo%2Byear:1939 in postman I also got no results. Replacing "%2B" with "+" showed me results again.

Any advice? I probably just oversee some simple issue.

Greetings,
Zacharias

Originally created by @Zacharias3D on GitHub (Jan 10, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/768 Hi everyone, I am trying to use the `search`-function to query for a specific song from a specific year. To accomplish this I call the `search`-function with `q=track:Chattanooga Choo Choo+year:1939`. This works just fine when trying the request in postman, but when executing it in Python I do not get any results. When I debugged, I realized that in the `_encode_params()`-function of the models-module in requests-lib, my query string is encoded which leads to the replacement of the joining "+" in my query-string ("+" becomes "%2B"). It seems though, that the Spotify API needs a "+" and not a URI-encoded "+". When trying the query-string `track:Chattanooga%20Choo%20Choo%2Byear:1939` in postman I also got no results. Replacing "%2B" with "+" showed me results again. Any advice? I probably just oversee some simple issue. Greetings, Zacharias
kerem 2026-02-27 23:22:48 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@Peter-Schorn commented on GitHub (Jan 11, 2022):

A literal + character must be percent-encoded to %2B, otherwise is the percent-encoded form of the space character. (A space character can also be percent-encoded as %20).

When you make the request in Postman, it assumes that the + is already the percent-encoded form of the space character. Therefore, the percent-decoded form of the q query parameter value in the Postman request is track:Chattanooga Choo Choo year:1939. Notice there is no + character. This is what you're searching for in Postman.

spotipy, on the other hand, will percent-encode the query, even if it is already percent-encoded. Therefore, it will percent-encode the + character to %2B. Therefore, the percent-decoded form of the q query parameter value in the spotipy request is track:Chattanooga Choo Choo+year:1939, which is exactly (and always will be) what you passed in to the search method originally. Do not percent-encode the query yourself beforehand. There is no track named Chattanooga Choo Choo+ (with a + character), so you get no results.

<!-- gh-comment-id:1010252991 --> @Peter-Schorn commented on GitHub (Jan 11, 2022): A literal `+` character must be percent-encoded to `%2B`, otherwise is the percent-encoded form of the space character. (A space character can also be percent-encoded as `%20`). When you make the request in Postman, it assumes that the `+` is already the percent-encoded form of the space character. Therefore, the percent-decoded form of the `q` query parameter value in the Postman request is `track:Chattanooga Choo Choo year:1939`. Notice there is no `+` character. This is what you're searching for in Postman. spotipy, on the other hand, will percent-encode the query, even if it is already percent-encoded. Therefore, it will percent-encode the `+` character to `%2B`. Therefore, the percent-decoded form of the `q` query parameter value in the *spotipy* request is `track:Chattanooga Choo Choo+year:1939`, which is exactly (and always will be) what you passed in to the `search` method originally. Do not percent-encode the query yourself beforehand. There is no track named `Chattanooga Choo Choo+` (with a `+` character), so you get no results.
Author
Owner

@Zacharias3D commented on GitHub (Jan 11, 2022):

Oh my god..

Thanks so much. Who would have thought that a "+" too much would cost me hours of my day.

Thanks a lot!!!

<!-- gh-comment-id:1010275457 --> @Zacharias3D commented on GitHub (Jan 11, 2022): Oh my god.. Thanks so much. Who would have thought that a "+" too much would cost me hours of my day. Thanks a lot!!!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#467
No description provided.