#๐Ÿ”’ werkzeug flask problem

55 messages ยท Page 1 of 1 (latest)

final seal
#

I've never had this problem before, but for some reason since i containerised by project with Docker, a super simple login view, ```py
@views.route("/login", methods=["GET", "POST"])
def login():
print("a")
if request.method == "POST":
print("b")
email = request.form.get("email")
password = request.form.get("password")

    user = User.query.filter_by(email=email).first()
    if user:
        print(user.password, password)
        if check_password_hash(user.password, password):
            login_user(user, remember=True)
            
            return redirect(url_for("views.account"))
        else:
            flash("Incorrect email or password", category="error")
    else:
        flash("No account with this email found. Please create an account", category="error")
    
return render_template("login.html", user=current_user)``` 

neither a or b are getting printed, but the program is failing on File "/views.py", line 594, in login if check_password_hash(user.password, password): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm not sure why this is happening as the database is populated with data

fickle houndBOT
#

@final seal

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

silver whale
#

Maybe if we had the full error we could help ๐Ÿค”

Maybe this might be the issue but we cant help because there is no info

 File "/views.py", line 594, in login
    if check_password_hash(user.password, password):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^```
๐Ÿค”
#

it would help

final seal
#
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1536, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1514, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/views.py", line 594, in login
    if check_password_hash(user.password, password):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/werkzeug/security.py", line 131, in check_password_hash
    return hmac.compare_digest(_hash_internal(method, salt, password)[0], hashval)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/werkzeug/security.py", line 28, in _hash_internal
    password_bytes = password.encode()
                     ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'encode'```
silver whale
#

like alot

#
  File "/usr/local/lib/python3.12/site-packages/werkzeug/security.py", line 28, in _hash_internal
    password_bytes = password.encode()
                     ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'encode'```
#

this might be the issue if you used your googly eyes

#

they can be found behind the eye lids embeded into the skull

final seal
#

Yes but what i'm saying is that user.password is not None, and password is not None as the data is being passed from the form correctly and from the db correctly

silver whale
#

right but can you give context on the password encoding

#

since thats really the only issue i can see

final seal
#

Or im unsure if this may be a problem with my container

silver whale
#

your just blindly trusting the output

final seal
final seal
silver whale
#

i see

#

but try printing the password and email before doing anything else and send result

#

lets just make sure

final seal
#

This is what im saying, nothings printing because of the check_password_hash

silver whale
#

so even if you do

email = request.form.get("email")
        password = request.form.get("password")
print(password, email)``` it wont run?
#

makes no sense

final seal
#

Like i said in my initial message print("a") if request.method == "POST": print("b") neither of these print with the login logic in

final seal
silver whale
#

so are you even executing the login function right? is it even being executed by the route?

final seal
#

Well it renders the template if it's not a POST, and the error only occurs when the forms submitted

silver whale
#

okay so show me

#

if its not executing that code block when you want it

#

show us

#

we cant read your code through your mind

#

but im pretty sure the password.encode() is the soul issue

#

unless your not properly checking user

#

also why not just use aes or another lib for obfuscating/hashing/encrypting passwords over werkzeug

#

have you tried that?

final seal
final seal
silver whale
#

ok i see i understand a bit more i was missing some

#

try swapping to something else

#

for the time being for debugging

#

so use base64 for the moment

#

as an example

#

use what you want but you get it

#

could just use pyaes thats what i would use

#
    def encode(source):
    
        password = "s3cr3t*c0d3"
        passwordSalt = os.urandom(16)
        key = pbkdf2.PBKDF2(password, passwordSalt).read(32)

        iv = pyaes.Counter(secrets.randbits(256))
        
        aes = pyaes.AESModeOfOperationCTR(key, iv)
        
        print(f'Iv: {iv}\nKey: {key}')

        source = aes.encrypt(bytes(source))```
#

i am using the pbkdf2 pypi here too

final seal
#

I'm unsure why but running it outside of the container, and everythings prints and it works perfectly, although as soon as i run it through the docker image this error arises, i think i'll look at re configuring my docker setup lol

#

thanks for your help although it wouldn't hurt to be a bit less insulting next time you help someone ๐Ÿ‘

final seal
#

yeah i'm fairly new to docker so may be a user error, thanks anyway

#

!close

fickle houndBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.