Python 本地服务器未更新
我开始学习烧瓶,所以我是这方面的新手,但我已经没有想法去实现了,这就是我来这里问的原因。我有一个python脚本,它向API发出GET请求,并返回一个QRcode,然后我得到QRcode并将其添加到html中,一切正常 但是我有这个代码检查API给我的JSON响应,它有三个响应:“加载”、“验证”和“获得qr码” 我得到的答复是Python 本地服务器未更新,python,http,flask,request,Python,Http,Flask,Request,我开始学习烧瓶,所以我是这方面的新手,但我已经没有想法去实现了,这就是我来这里问的原因。我有一个python脚本,它向API发出GET请求,并返回一个QRcode,然后我得到QRcode并将其添加到html中,一切正常 但是我有这个代码检查API给我的JSON响应,它有三个响应:“加载”、“验证”和“获得qr码” 我得到的答复是200 我在互联网上到处搜索,看看是否有人和我有同样的问题,但我没有找到一个人有这个问题。 我已尝试重新启动以下程序 重新启动我的本地服务器 在app.run()中实现调
200
我在互联网上到处搜索,看看是否有人和我有同样的问题,但我没有找到一个人有这个问题。
我已尝试重新启动以下程序
提前感谢。移动您的
请求。根据索引()中的获取和所有后续对象:
当前,您的请求
未刷新到服务器启动点之后。但是,如果您每次访问站点的根页面时都将其移动到@app.route(“/”
)中,它将执行一个新的requests.get()
,以刷新您的数据。移动请求。根据索引()
中的请求获取和所有后续对象:
当前,您的请求
未刷新到服务器启动点之后。但是,如果每次访问站点的根页面时将其移动到@app.route(“/”
)中,它将执行一个新的requests.get()
,以刷新数据。请更新您的问题,并添加运行脚本时获得的输出。另外,您是否验证了req.status\u code
是否为200
?是否可以将req
、json\u内容
和parse\u json
移动到def index()
中?目前,服务器启动时,您的请求
只会获取
一次。@Idlehands是正确的,这些行应该在索引
函数中。另外,在尝试解析请求之前,我会检查请求状态。请更新您的问题,添加运行脚本时获得的输出。另外,您是否验证了req.status\u code
是否为200
?是否可以将req
、json\u内容
和parse\u json
移动到def index()
中?目前,服务器启动时,您的请求
只会获取
一次。@Idlehands是正确的,这些行应该在索引
函数中。在尝试解析之前,我还会检查请求的状态
req = requests.get('this is the link with my API token')
json_content = req.content
# parsed JSON content, ready to use
parsed_json = json.loads(json_content)
@app.route("/")
def index():
if parsed_json["accountStatus"] == "loading":
print(parsed_json["accountStatus"])
print(req.status_code)
return render_template("loading.html")
if parsed_json["accountStatus"] == "got qr code":
print(parsed_json["accountStatus"])
str_parsed_json = yaml.safe_load(parsed_json["qrCode"])
print(req.status_code)
return render_template("qrcodePage.html", str_parsed_json=str_parsed_json)
if parsed_json["accountStatus"] == "authenticated":
print(parsed_json["accountStatus"])
print(req.status_code)
return render_template("index.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
@app.route("/")
def index():
req = requests.get('this is the link with my API token')
json_content = req.content
# parsed JSON content, ready to use
parsed_json = json.loads(json_content)
if parsed_json["accountStatus"] == "loading":
print(parsed_json["accountStatus"])
return render_template("loading.html")
... rest of your code