mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-06 14:52:50 +00:00
improve handling of err responses with no payload
This commit is contained in:
parent
44bbfac8b7
commit
23d75aa4c6
26
examples/audio_features_for_track.py
Normal file
26
examples/audio_features_for_track.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# shows acoustic features for tracks for the given artist
|
||||||
|
|
||||||
|
from __future__ import print_function # (at top of module)
|
||||||
|
from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
|
import json
|
||||||
|
import spotipy
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
client_credentials_manager = SpotifyClientCredentials()
|
||||||
|
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
||||||
|
sp.trace=True
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
tids = sys.argv[1:]
|
||||||
|
print(tids)
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
features = sp.audio_features(tids)
|
||||||
|
delta = time.time() - start
|
||||||
|
print ("features", features)
|
||||||
|
print(json.dumps(features, indent=4))
|
||||||
|
print ("features retrieved in %.2f seconds" % (delta,))
|
23
examples/errors.py
Normal file
23
examples/errors.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# shows acoustic features for tracks for the given artist
|
||||||
|
|
||||||
|
from __future__ import print_function # (at top of module)
|
||||||
|
from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
|
import json
|
||||||
|
import spotipy
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
client_credentials_manager = SpotifyClientCredentials()
|
||||||
|
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
||||||
|
sp.trace=True
|
||||||
|
try:
|
||||||
|
print ('bad call 0')
|
||||||
|
bad_artist_call = sp.artist('spotify:artist:12341234')
|
||||||
|
except spotipy.client.SpotifyException:
|
||||||
|
print ('bad call 0 exception' )
|
||||||
|
|
||||||
|
print ('bad call 1')
|
||||||
|
bad_artist_call = sp.artist('spotify:artist:12341234')
|
||||||
|
print ('bad artist', bad_artist_call)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user