【发布时间】:2017-08-28 21:49:19
【问题描述】:
我正在尝试运行 Spotipy 文档中的一些简单代码:
scope = 'user-library-read'
if len(sys.argv) > 1:
username = sys.argv[1]
else:
print ("Usage: %s username" % (sys.argv[0],))
sys.exit()
token = util.prompt_for_user_token(username, scope)
我已经尝试通过运行以下命令在终端 (Ubuntu) 中设置我的凭据:
$ export SPOTIPY_CLIENT_ID='[my id]'
$ export SPOTIPY_CLIENT_SECRET='[my secret]'
$ export SPOTIPY_REDIRECT_URI='localhost:8888/callback'
不过,我明白了:
You need to set your Spotify API credentials. You can do this by
setting environment variables like so:
export SPOTIPY_CLIENT_ID='your-spotify-client-id'
export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
export SPOTIPY_REDIRECT_URI='your-app-redirect-url'
Get your credentials at
https://developer.spotify.com/my-applications
---------------------------------------------------------------------------
SpotifyException Traceback (most recent call last)
<ipython-input-13-e24370a9caf8> in <module>()
7 sys.exit()
8
----> 9 token = util.prompt_for_user_token(username, scope)
/home/user/anaconda3/envs/Python3/lib/python3.6/site-packages/spotipy/util.py in prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
45 https://developer.spotify.com/my-applications
46 ''')
---> 47 raise spotipy.SpotifyException(550, -1, 'no credentials set')
48
49 sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri,
SpotifyException: http status: 550, code:-1 - no credentials set
我做错了什么?我无法在任何地方找到有关如何解决此问题的完整纲要。
提前感谢您的帮助。
【问题讨论】:
-
$ export SPOTIPY_REDIRECT_URI='ocalhost:8888/callback'....ocalhost? -
打错字了,抱歉,已编辑
-
尝试直接在python中定义凭证:
util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) -
@sKwa 确实给了我提示,谢谢。但我收到这条消息:
User authentication requires interaction with your web browser. Once you enter your credentials and give authorization, you will be redirected to a url. Paste that url you were directed to to complete the authorization.如果我输入 URL,我会收到SpotifyOauthError: Bad Request。 -
如何运行脚本?尝试在运行代码之前询问
ipython中的变量:os.getenv('<YOUR VARIABLE>')。可能是您使用不同的终端会话并且未导出变量,即执行export ...->ipython-> 运行代码。