0
votes

I am trying to build a user login system and I have successfully built the user register page, but when I try to login I get the error below. I am using flask, python3.6 and pymongo. This is the error: AttributeError: 'bytes' object has no attribute 'encode' please help.

Traceback (most recent call last): File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2309, in call return self.wsgi_app(environ, start_response) File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2295, in wsgi_app response = self.handle_exception(e) File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1741, in handle_exception reraise(exc_type, exc_value, tb) File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_compat.py", line 35, in reraise raise value File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_compat.py", line 35, in reraise raise value File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\elvis\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functionsrule.endpoint File "C:\Users\elvis\Desktop\flask apps\testmon\even\app\run.py", line 30, in login if bcrypt.hashpw(request.form['pass'].encode('utf-8'), login_user['password']) == login_user['password'].encode('utf-8'): AttributeError: 'bytes' object has no attribute 'encode'

(a screenshot of the error page)

2
See this SO question for example.Jeroen Heier
Please show us the relevant code (see also stackoverflow.com/help/on-topic , "Questions seeking debugging help" section). Best regardsYakovL

2 Answers

0
votes

Only give the Password=" "

Example:

pdf = pdfplumber.open(f,password='')
0
votes

The last line of the traceback

login_user['password']) == login_user['password'].encode('utf-8'): AttributeError: 'bytes' object has no attribute 'encode'

Tells you that you are passing an object that is of type bytes, not a str.
So you are trying to invoke .encode() method on bytes object.
You need to check what is the login_user['password'] value, and either cast it to string by invoking decode() method on the bytes object login_user['password']).decode().encode('utf-8') or store a string value in this dictionary at the beginning.

From this traceback I can see, that what you're doing doesn't make much sense, but unless you can share the code, there is not much more I can tell.

EDIT:

login if bcrypt.hashpw(request.form['pass'].encode('utf-8'), login_user['password']) == login_user['password'].encode('utf-8'): AttributeError: 'bytes' object has no attribute 'encode'

You can also probably remove the .endoce('utf-8') from the login_user['password'] part, and it could work as well.