Help with code! "Too many values to unpack"

Code:

def view():
    with open("passwords.txt", 'r') as f:
        for line in f.readlines():
            data = line.rstrip()
            user, passw = data.split("|")
            print("User:", user, "| Password:", passw)

Error message:

`File "c:\Users\Josh Lee\Python\Hello World\password_manager.py", line 27, in <module>
    view()
  File "c:\Users\Josh Lee\Python\Hello World\password_manager.py", line 8, in view
    user, passw = data.split("|")
ValueError: too many values to unpack (expected 2)

This is my code. I have tried to change line 8, but it’ll say too little expected (expected: 2 got:1) and then it’ll show this. I’ve been stuck on this for a while and would like some pointers on where I can improve the code

Please don’t post screenshots.

Copy and paste any code or traceback, and in order to preserve formatting, select the code or traceback that you posted and then click the </> button.

What is the value of data? What is the value of data.split("|")? Print them out to check what they actually are.

Also, I find it strange that the code says data.split("|") but the traceback appears to say data.split("| "). Note the extra space in the string.

ok i got rid of the screenshot, thanks! ok ill play around with it and see if anything changes but so far it still hasn’t worked

It seems the problem is that some line do not have a “|” character, thus data.split("|") does not return two parts but one.