0

I get this error in register in pset8/finance when I run check50:

:) application.py exists

:) application starts up

:) register page has all required elements

:( registering user succeeds expected status code 200, but got 400

:) registration with an empty field fails

:) registration with password mismatch fails

:( registration rejects duplicate username expected status code 200, but got 400 :) login page has all required elements

@app.route("/register", methods=["GET", "POST"])

def register(): """Register user"""

# User reached route via POST (as by submitting a form via POST)
if request.method == "POST":

    # Assign inputs to variables
    input_username = request.form.get("username")
    input_password = request.form.get("password")
    input_confirmation = request.form.get("confirmation")

    # Ensure username was submitted
    if not input_username:
        return apology("must provide username", 400)

    # Ensure password was submitted
    elif not input_password:
        return apology("must provide password", 400)

    # Ensure passwsord confirmation was submitted
    elif not input_confirmation:
        return apology("must provide password confirmation", 400)

    elif not input_password == input_confirmation:
        return apology("passwords must match", 400)

    # Query database for username
    username = db.execute("SELECT username FROM users WHERE username = :username",
                      username = input_username)

    # Ensure username is not already taken
    if len(username) == 1:
        return apology("sorry, username is already taken", 403)

    # Query database to insert new user
    else:
        new_user = db.execute("INSERT INTO users (username, hash) VALUES (:username, :password)",
                        username = input_username,
                        password = generate_password_hash(input_password, method="pbkdf2:sha256", salt_length=8))

        if new_user:
            # Keep newly registered user logged in
            session["user_id"] = new_user

        # Flash info for the user
        flash(f"Registered as {input_username}")

        # Redirect user to homepage
        return redirect("/")

# User reached route via GET (as by clicking a link or via redirect)
else:
    return render_template("register.html")

1 Answer 1

0

This warning from the spec:

Be aware that check50 will test your entire program as a whole. If you run it before completing all required functions, it may report errors on functions that are actually correct but depend on other functions.

It is likely the 400 is from the distro index function.

2
  • I did all the required functions and made all the pages but still it is showing Oct 3, 2021 at 16:34
  • A repro with this register only fails the duplicate test (because it returns 403 instead of 400 from apology). That indicates a likely problem with index. Perhaps edit the question and add the link to check50 and the index function from application.py. Oct 3, 2021 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .