How to deal with HTTP Status 400, Code: -1 when using the search function in Spotify API through Spotipy

Viewed 18

So I recently started using Spotify's API through Spotipy library in Python for a school project. The objective of our project is to analyze the songs in Billboard HOT 100 since 1960. I got the data for all the Billboard songs and wrote a code to get the Spotify URIs for all these songs using Search query provided by the API using Spotipy.

I am getting a Spotify Exception with HTTP Status: 400, Code: -1, for the following line of code,

sp.search(q="track: A Rockin' Good Way (To Mess Around and Fall in Love) artist: Dinah Washington & Brook Benton year: 1960",type='track') 

Here, sp is the Spotify client.

I assumed this had something to do with the string quotes or the ampersand (&) but it doesn't seem to be the case because I have tried all possible combinations.

I would like to know how to deal with this.

Thank you.


Error Message:

HTTPError                                 Traceback (most recent call last)
~\anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params)
    244 
--> 245             response.raise_for_status()
    246             results = response.json()

~\anaconda3\lib\site-packages\requests\models.py in raise_for_status(self)
    942         if http_error_msg:
--> 943             raise HTTPError(http_error_msg, response=self)
    944 

HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/search?q=track%3A%22A+Rockin%27+Good+Way+%28To+Mess+Around+and+Fall+in+Love%29%22+artist%3A+%22Dinah+Washington+%26+Brook+Benton%22+year%3A+1960&limit=10&offset=0&type=track

During handling of the above exception, another exception occurred:

SpotifyException                          Traceback (most recent call last)
<ipython-input-66-78c961aa8b06> in <module>
----> 1 sp.search(q="""track:"A Rockin' Good Way (To Mess Around and Fall in Love)" artist: "Dinah Washington & Brook Benton" year: 1960""",type='track')

~\anaconda3\lib\site-packages\spotipy\client.py in search(self, q, limit, offset, type, market)
    551                            from_token.
    552         """
--> 553         return self._get(
    554             "search", q=q, limit=limit, offset=offset, type=type, market=market
    555         )

~\anaconda3\lib\site-packages\spotipy\client.py in _get(self, url, args, payload, **kwargs)
    295             kwargs.update(args)
    296 
--> 297         return self._internal_call("GET", url, payload, kwargs)
    298 
    299     def _post(self, url, args=None, payload=None, **kwargs):

~\anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params)
    265             )
    266 
--> 267             raise SpotifyException(
    268                 response.status_code,
    269                 -1,

SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/search?q=track%3A%22A+Rockin%27+Good+Way+%28To+Mess+Around+and+Fall+in+Love%29%22+artist%3A+%22Dinah+Washington+%26+Brook+Benton%22+year%3A+1960&limit=10&offset=0&type=track:
 Bad request., reason: None
0 Answers
Related