Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alirezadigi opened this issue Oct 27, 2023 · 4 comments
Open
Labels
CS50x CS50x

Comments

@alirezadigi
Copy link

alirezadigi commented Oct 27, 2023

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
@alirezadigi alirezadigi changed the title finance week 9 , false error finance week 9 , false error ( expected status code 200, but got 302 ) Oct 27, 2023
@pavsoldatov
Copy link

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
Copy link

pavsoldatov commented Dec 8, 2023

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
Copy link

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

@rongxin-liu rongxin-liu added the CS50x CS50x label Feb 6, 2024
@Timothy-Corder
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CS50x CS50x
Projects
None yet
Development

No branches or pull requests

4 participants