简体   繁体   中英

Why do I get IndexError: list index out of range

To explain you my Problem, my Client sends a username and password... The Client format it like this

file = salt + username + "splitme" + salt + password encrypt file via tls (when connecting to server)

Send to Server

server decrypts the file and trys to split at "splitme"

CODE:

data = data.split("splitme", 1)

    username_salted = data[0]
    password_salted = data[1]

And then Python stops the program and says

password_salted = data[1] IndexError: list index out of range

I don't know whats the problem...

Because data is a list of 1 element, since the first element access did not raise an error.

Did you decode data ? Did it succeed? data probably does not contain "splitme", in which case you get a list with the whole content you tried to split as the only element.

Have you verified the contents of data ? Do you have access to the source code? Can you run it? In that case, you can either change the code for some extra logging, run a debugger such as ipdb3 or use the trace module to see what gets executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM