Help with not enough values to unpack error

#I am not sure what to do…I get not enough values to unpack error and I am not sure how to fix it.

openFile = open("applog.txt", "r")
userInput = input("Please enter an IP octet: ")
lines = openFile.readlines()
IPlist = []
count = 0

for parts in lines:
        node, IP, text = parts.split(" - ", 2)
        IPsplit = IP.split(".")
        if IPsplit[1] == userInput or IPsplit[2] == userInput:
            IPlist.insert(count, parts)
            count += 1
openFile.close()
if len(IPlist) == 0:
    print("That octet is not in the file")
else:
    octetFound = len(IPlist)
    print(octetFound)

Thank you for posting your code. It would help if you also posted the
full trackback, as that usually pinpoints the exact line where the error
occurred and the call chain (though there are no functions in your code,
so there’s no call chain in this case).

Just looking at your code, it is probably this line:

 node, IP, text = parts.split(" - ", 2)

This suggests that your line is not broken into enough fields by the
.split() call. Print out the line!

 print(repr(parts))

and print out the result of the split():

 print(repr(parts.split(" - ", 2)))

Put these before your assignment statement. This should show you the
offending line and what .split() actually gave you.

Cheers,
Cameron Simpson cs@cskk.id.au

2 Likes