0

First of all, sorry for the vague title as I wasn't sure what to call it.

Here is the issue I'm having, I'm creating a dict structure like so:

requestDict["001"]["request"] = "GET / HTTP..."

requestDict["001"]["response"] = "HTTP 1.1 OK..."

etc.

But this isn't working

def fiddler_convert(filename):
archive = zipfile.ZipFile(filename, "r")

requestDict = {}

for name in archive.namelist():
    if name.find(".txt") != -1: 
        requestNum = (name.split("_")[0]).split("/")[1]
        requestDict[requestNum] = {}

        if name.find("_c.txt"):
            requestDict[requestNum]["request"] = archive.read(name)
        elif name.find("_s.txt"):
            requestDict[requestNum]["response"] = archive.read(name)
        else:
            print "wat"

for key, value in requestDict:
    print key + ":" + value

archive.close()

I get an error of for key, value in requestDict: ValueError: too many values to unpack

Why is this? The type of each value is just a string ie "001", "002", etc.

Wondering if anyone has any ideas? The input is all good (ie. requestNum variable is set correct to "001" and archive.read(name) is good).

1 Answer 1

5

The values returned by a dictionary iterator are keys, not tuples (key, value). Consider using items(), or iteritems() instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Huh, yea that worked - I think I need too read a bit more into python. Thanks, will mark as answer when I can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.