values = data.split("\x00")
username, passwordHash, startRoom, originUrl, bs64encode = values
if len(passwordHash)!= 0 and len(passwordHash)!= 64:
passwordHash = ""
if passwordHash != "":
passwordHash = hashlib.sha512(passwordHash).hexdigest()
username = username.replace("<", "")
if len(startRoom) > 200:
startRoom = ""
startRoom = self.roomNameStrip(startRoom, "2").replace("<","").replace("&#", "&amp;#")
self.login(username, passwordHash, startRoom, originUrl)
Error:
username, passwordHash, startRoom, originUrl, bs64encode = values
ValueError: too many values to unpack
Asked
Active
Viewed 4.2k times
-4
-
2I'd suggest adding some text to state the question, instead of just posting code. It's likely to get your question upvoted more, and therefore more people will see it, and you'll be more likely to get an answer. – Dave Challis Jun 13 '14 at 19:45
2 Answers
9
Check the output of
print len(values)
It has more than 5 values (which is the number of variables you are trying to "unpack" it to) which is causing your "too many values to unpack" error:
username, passwordHash, startRoom, originUrl, bs64encode = values
If you want to ignore the tail end elements of your list, you can do the following:
#assuming values has a length of 6
username, passwordHash, startRoom, originUrl, bs64encode, _ = values
or unpack only the first 5 elements (thanks to @JoelCornett)
#get the first 5 elements from the list
username, passwordHash, startRoom, originUrl, bs64encode = values[:5]
![](../../users/profiles/276949.webp)
Martin Konecny
- 50,691
- 18
- 119
- 145
-
1Might be better to do `arg1, arg2, arg3 = values[:3]` to ignore extra elements. – Joel Cornett Jun 13 '14 at 19:41
-
0
When you're doing values = data.split("\x00")
it's producing more then 5 elements, probably not all values are separated by \x00
.
Inspect the value of values
with print values
and check it's size with len(values)
![](../../users/profiles/498227.webp)
Magnun Leno
- 2,348
- 18
- 27