Wolf_Yout
@Wolf_Yout

Flask возвращает ошибку 'Request' object has no attribute 'args', что делать?

Код трёх страниц:
from flask import Flask, render_template, session, redirect, url_for, request

@app.route("/")
def index():
    if "id" in session:
        user = disnake.fetch_user(session.get("id"))
        return render_template("index.html",bot_name=bot.user.name,servers=len(bot.guilds),users=len(bot.users),user_name=user.name)
    else:
        return render_template("index.html",bot_name=bot.user.name,servers=len(bot.guilds),users=len(bot.users),user_name=None)

@app.route("/login")
def log_in():
    if not "id" in session:
        return redirect("https://discord.com/api/oauth2/authorize?client_id=1047125592220373075&redirect_uri=http%3A%2F%2Fde4.bot-hosting.net%3A7259%2Fsave_me&response_type=code&scope=identify%20guilds%20email")
    else:
        return redirect(url_for("save_me"))

@app.route("/save_me", methods = ["get"])
def save_me():
    code = request.args.get("code", "")
    at = Oauth.get_access_token(code)

    user = Oauth.get_user_json(at)
    session["id"] = user.get("id")
    return redirect("http://de4.bot-hosting.net:7259/")

При переходе на страницу save_me(точнее после перенаправления) страница выглядит так:
image.png
А в консоли ошибка:
[2023-01-08 08:10:16,404] ERROR in app: Exception on /save_me [GET]
Traceback (most recent call last):
  File "/home/container/.local/lib/python3.9/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/container/.local/lib/python3.9/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/container/.local/lib/python3.9/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/container/.local/lib/python3.9/site-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/home/container/main.py", line 1803, in save_me
    code = request.args.get("code", "")
AttributeError: 'Request' object has no attribute 'args'
  • Вопрос задан
  • 76 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы