cs50 / problems

Checks for check50
142 stars 233 forks source link

finance week 9 , false error ( expected status code 200, but got 302 ) #202

Open alirezadigi opened 1 year ago

alirezadigi commented 1 year ago

hi , i get this error while my code requires redirect so it do need 302 status code please help me if there is anything i should do

:( logging in as registered user succceeds
    expected status code 200, but got 302

i can fix this error by changing my decorated_function like this (in helpers.py), but it breaks other tests and other parts of program

def login_required(f):
    """
    Decorate routes to require login.

    http://flask.pocoo.org/docs/0.12/patterns/viewdecorators/
    """
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if session.get("user_id") is None:
            return redirect("/login",200)
        return f(*args, **kwargs)
    return decorated_function
pavsoldatov commented 11 months ago

I concur. I have the same problem and I honestly don't even know where to look, because the Network tab gives me the same responses on log in as the official solution at https://finance.cs50.net/

Furthermore, if I spam the check50, some.times this specific test passes. Most of the times it does not. I am at a point of breaking the academic honesty. The test error message also changes from time to time in response to my changes. It used to be the one in the title, now it is as follows:

sending GET request to /signin
sending POST request to /login
exception raised in application: IndexError: list index out of range

Needless to say the app works well if you test it manually. It would help to actually have access to the tests and see what they test for.

pavsoldatov commented 11 months ago

The test results are also very inconsistent. Without changing the code, I sometimes get the respective test to pass by spam-running the test suite. The logs:

  1. IndexError... https://submit.cs50.io/check50/2631d3c32442ca5c6ec6ffe3e0ed49ef15324381
  2. 302 Error (it all started with this error, which shouldn't even be an issue because it is a redirect, no?) https://submit.cs50.io/check50/ba3f21224554c681b26931362331071ded703eee
  3. Weirdly enough a success: https://submit.cs50.io/check50/9c66fa03d12b305bcb9b02e2982e60868351fd1f
  4. Back to square one with the index error.

The only difference between the code there is that I tried implementing a '/signin' route that would simply redirect to '/login' or '/register'

I claim the test "logging in as registered user succceeds" is inconsistent.

pavsoldatov commented 11 months ago

Ok, i found the solution to this: If in app.py, you call any custom function you created, then YOU SHOULD NOT externalize them in another file! They must be written in app.py, so at the end of the file.

I don't know how tests are processed, but the test doesn't expect that we organize the code in order to reduce redundancy, externalize logical code outside of the file etc.

Source: https://cs50.stackexchange.com/questions/43114/check50-is-broken-on-problem-set-9-finance

Timothy-Corder commented 2 months ago

Can confirm, I also have this problem

        flash('Successfully logged in!')
        response = redirect("/", 200)
        print(response.status_code)
        print(response)
        return (response, 200)

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

Above is a segment of my own code. It works perfectly from all points of view except for check50. I am losing my mind.