Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 授权代码流Spotify中的错误请求_Python_Spotipy - Fatal编程技术网

Python 授权代码流Spotify中的错误请求

Python 授权代码流Spotify中的错误请求,python,spotipy,Python,Spotipy,我试图构建一个脚本,在用户的spotify配置文件上创建一个播放列表。为了学习spotipy,我决定尝试文档页面上的示例 我运行的代码是: import sys import spotipy import spotipy.util as util token = util.prompt_for_user_token('idxxx', 'user-library-read', client

我试图构建一个脚本,在用户的spotify配置文件上创建一个播放列表。为了学习spotipy,我决定尝试文档页面上的示例

我运行的代码是:

import sys
import spotipy
import spotipy.util as util

token = util.prompt_for_user_token('idxxx',
                           'user-library-read',
                           client_id='axxx',
                           client_secret='Bxxx',
                           redirect_uri='http://localhost')

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)

if token:
    sp = spotipy.Spotify(auth=token)
    results = sp.current_user_saved_tracks()
    for item in results['items']:
        track = item['track']
        print(track['name'] + ' - ' + track['artists'][0]['name'])
else:
    print("Can't get token for", username)
当我运行代码时,问题就出现了。我在重定向uri上被重定向,在我将其粘贴回终端后,我得到以下结果:

Traceback (most recent call last):
  File "spot01.py", line 9, in <module>
    redirect_uri='http://localhost')
  File "/home/user/.local/lib/python3.6/site-packages/spotipy/util.py", line 92, in prompt_for_user_token
    token = sp_oauth.get_access_token(code, as_dict=False)
  File "/home/user/.local/lib/python3.6/site-packages/spotipy/oauth2.py", line 434, in get_access_token
    raise SpotifyOauthError(response.reason)
spotipy.oauth2.SpotifyOauthError: Bad Request
回溯(最近一次呼叫最后一次):
文件“spot01.py”,第9行,在
重定向http://localhost')
文件“/home/user/.local/lib/python3.6/site packages/spotipy/util.py”,第92行,提示输入用户令牌
token=sp\u oauth.get\u access\u token(代码,as\u dict=False)
文件“/home/user/.local/lib/python3.6/site packages/spotipy/oauth2.py”,第434行,在get\u access\u令牌中
引发SpotifyOauthError(response.reason)
spotipy.oauth2.spotifyOAutheror:请求错误
我试图从文件管理器和终端访问oauth2.py,但它说这个存储库不存在。我还试图通过github页面安装spotipy,他们有必要的文件,但仍然没有

有什么想法吗?
非常感谢。

我从这里下载了所需的文件,解决了这个问题

然后我更改了每个.py文件中的一些内容,并在其中运行了我想要的所有代码。这一定是另一个更为奇特的解决方案,但这一个对我有效

哦,在运行任何命令之前,我在终端上键入了这组命令:

$ bash
$ export SPOTIPY_CLIENT_ID='xxx'
$ export SPOTIPY_CLIENT_SECRET='xxx'
$ export SPOTIPY_REDIRECT_URI='http://localhost/'

您可以将您的凭证放在其中,并将您的本地主机或github配置文件链接放在refrect uri上。

我通过从这里下载所需的文件解决了这个问题

然后我更改了每个.py文件中的一些内容,并在其中运行了我想要的所有代码。这一定是另一个更为奇特的解决方案,但这一个对我有效

哦,在运行任何命令之前,我在终端上键入了这组命令:

$ bash
$ export SPOTIPY_CLIENT_ID='xxx'
$ export SPOTIPY_CLIENT_SECRET='xxx'
$ export SPOTIPY_REDIRECT_URI='http://localhost/'
您将凭证放在其中,并在refirect uri上显示您的本地主机或github配置文件链接