[GH-ISSUE #443] AttributeError: __exit__ when using search() #259

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

Originally created by @ChairMane on GitHub (Feb 18, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/443

I tried using the example from the README, with the code below:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import json

config = json.load(open("config.json"))

cid = config['spotify_client']
secret = config['spotify_secret']

client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

results = sp.search(q='weezer', limit=20)
print(results['tracks']['items'])
for idx, track in enumerate(results['tracks']['items']):
    print(idx, track['name'])

The only thing I'm doing different are how I give the client ID and client secret. When I try running this code, I get the following error:

Traceback (most recent call last):
  File "spotifyDataset.py", line 14, in <module>
    results = sp.search(q='weezer', limit=20)
  File "lib/python3.5/site-packages/spotipy/client.py", line 401, in search
    "search", q=q, limit=limit, offset=offset, type=type, market=market
  File "lib/python3.5/site-packages/spotipy/client.py", line 193, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/lib/python3.5/site-packages/spotipy/client.py", line 150, in _internal_call
    method, url, headers=headers, proxies=self.proxies, **args
AttributeError: __exit__

Am I doing something incorrectly?

Originally created by @ChairMane on GitHub (Feb 18, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/443 I tried using the example from the README, with the code below: ```py import spotipy from spotipy.oauth2 import SpotifyClientCredentials import json config = json.load(open("config.json")) cid = config['spotify_client'] secret = config['spotify_secret'] client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret) sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) results = sp.search(q='weezer', limit=20) print(results['tracks']['items']) for idx, track in enumerate(results['tracks']['items']): print(idx, track['name']) ``` The only thing I'm doing different are how I give the client ID and client secret. When I try running this code, I get the following error: ``` Traceback (most recent call last): File "spotifyDataset.py", line 14, in <module> results = sp.search(q='weezer', limit=20) File "lib/python3.5/site-packages/spotipy/client.py", line 401, in search "search", q=q, limit=limit, offset=offset, type=type, market=market File "lib/python3.5/site-packages/spotipy/client.py", line 193, in _get return self._internal_call("GET", url, payload, kwargs) File "/lib/python3.5/site-packages/spotipy/client.py", line 150, in _internal_call method, url, headers=headers, proxies=self.proxies, **args AttributeError: __exit__ ``` Am I doing something incorrectly?
kerem closed this issue 2026-02-27 23:21:40 +03:00
Author
Owner

@stephanebruckert commented on GitHub (Feb 18, 2020):

Works for me. Does the initial example without modification work for you in a separate file? Were you including this in another application? The issue looks related to multi-threading

<!-- gh-comment-id:587279278 --> @stephanebruckert commented on GitHub (Feb 18, 2020): Works for me. Does the initial example without modification work for you in a separate file? Were you including this in another application? The issue looks related to multi-threading
Author
Owner

@ChairMane commented on GitHub (Feb 18, 2020):

Ok, so it ends up working if I do it in a separate file. I'm new to this multi-threading stuff, so I got lost easily. I appreciate it, Stephane!

<!-- gh-comment-id:587287681 --> @ChairMane commented on GitHub (Feb 18, 2020): Ok, so it ends up working if I do it in a separate file. I'm new to this multi-threading stuff, so I got lost easily. I appreciate it, Stephane!
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#259
No description provided.