Warm tip: This article is reproduced from serverfault.com, please click

python-使用Spotipy的Spotify身份验证未显示,并且我的重定向uri拒绝连接?

(python - Spotify authentication using Spotipy not showing and my redirect uri is refusing to connect?)

发布于 2020-12-02 09:44:32

使用Spotipy(使用Spotify API通过Spotify API访问数据)和Django,我尝试使用授权代码流进行身份验证,但是在使用登录路由时,我一直遇到错误。

使用路线http://localhost/?code=AQDaVeJPteLHVgQG7P41mX5XMmoriJtbpx7vjRYdTXBR64Fal2IMHXQfnSoEdrYrZnYwM-xjyyr_ME_t_gsbqR6-72A4sRBQZ1aaoJd7Xcr2rqT_9aF_kDND0XmZZMhRQzN4oAujH6Uawl9d-tEJmnE_Q-yISGAGTuIHlONwbPEretR9XdPXQg,出现错误的网址localhost refused to connectlogin

urls.py

urlpatterns = [
path("login/" , views.login , name = "login" ),
path("home/", views.home, name= "home"),
path("callback/" , views.callback , name="callback")
]

views.py

get_authorize_url()方法返回Spotify API端点 https://accounts.spotify.com/authorize?client_id=83654ff787fc48c7a38cc7976238628a&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2F&scope=user-library-read

def login(request):
   authorize_url = oauth.get_authorize_url()
   return redirect(authorize_url)

get_access_token() 返回访问令牌

def callback(request):
    code = request.GET.get("code")
    if code is not None:
        oauth.get_access_token(code)
        return redirect(reverse("home"))
    else:
        return redirect(reverse("login"))


def home(request):
     return HttpResponse("Welcome")
Questioner
Kwaku Biney
Viewed
0
Kwaku Biney 2020-12-02 18:11:02

我意识到http://localhost/是错误。在浏览器中键入它,并引发相同的错误。更改为redirect_urihttp://127.0.0.1:8000/spotify/callback/因此我被重定向回服务器和回调路由。