Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.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
500:内部服务器错误Spotify python验证代码流试图重定向到登录并获取令牌_Python_Api_Rest_Flask_Spotify - Fatal编程技术网

500:内部服务器错误Spotify python验证代码流试图重定向到登录并获取令牌

500:内部服务器错误Spotify python验证代码流试图重定向到登录并获取令牌,python,api,rest,flask,spotify,Python,Api,Rest,Flask,Spotify,我使用文档让用户登录并返回代码和状态。然而,当我运行我的应用程序时,它会给我一个500错误 这是我的app.py import flask import SpotifyOAuth app = flask.Flask(__name__) @app.route('/') def index(): flask.render_template("index.html") @app.route('/login') def accessSpotify(): Spot

我使用文档让用户登录并返回代码和状态。然而,当我运行我的应用程序时,它会给我一个500错误

这是我的app.py

import flask
import SpotifyOAuth

app = flask.Flask(__name__)

@app.route('/')
def index():
    flask.render_template("index.html")

@app.route('/login')
def accessSpotify():
    SpotifyOAuth.RedirectTologin(redirect_uri='https://localhost:7001/authorized')

@app.route('/authorized')
def SP_redirect_uri():
    return "spotify connected"

def main():
    print("nothin")

if __name__ == '__main__':
    app.run(use_reloader=True,port=7001)

这是我的SpotifyOAuth.py

import requests

def RedirectTologin(redirect_uri="https://localhost:7001/authorized"):
    token_uri="https://accounts.spotify.com/authorize"
    method="GET"
    params={
        "client_id" : '<id>',
        "response_type" : 'code',
        "redirect_uri" : redirect_uri,
        "scope" : 'user-read-email'
    }
    client_secret='<secret>'
    r = requests.get(token_uri,params=params)
    print(r)

if __name__=='__main__':
    RedirectTologin()
导入请求
def RedirectTologin(重定向_uri=”https://localhost:7001/authorized"):
令牌_uri=”https://accounts.spotify.com/authorize"
方法=“获取”
params={
“客户端id”:“”,
“响应类型”:“代码”,
“重定向uri”:重定向uri,
“范围”:“用户阅读电子邮件”
}
客户_机密=“”
r=requests.get(token_uri,params=params)
印刷品(r)
如果“名称”=“\uuuuuuuu主要”:
托洛金()
我知道我的RedirectLogin()正在工作,因为当我打印r时,它会给我响应代码200。不确定我在app.py中出错的地方

这是我的index.html供参考

<html>
<body>
 <div>
    <div id="login">
     <h1>First, log in to spotify</h1>
     <a href="/login">Log in</a>
    </div>
    <div id="loggedin">
    </div>
 </div>
</body>
</html>

首先,登录spotify

有人看到什么问题吗?我没有多少使用API的经验,我需要返回一些东西:呈现模板、重定向、带有状态代码的纯文本等等

要解决您的问题,您需要添加
return
s到
index()
accessSpotify()
,如下所示:

@app.route(“/”)
def index():
返回flask.render_模板(“index.html”)
@app.route(“/login”)
def accessSpotify():
SpotifyOAuth.RedirectTologin(redirect_-uri=)https://localhost:7001/authorized')
return flask.redirect(url_for('SP_redirect_uri'))