views:

29

answers:

1

I do:

con = HTTPConnection(SERVER_NAME)
con.request('GET', PATH, HEADERS)
resp = con.getresponse()

For debugging reasons, I want to see the request I used (it's fields, path, method,..). I would expect there to be some sort of con.getRequest() or something of the sort but didn't find anything. Ideas?

+1  A: 

Try

con.setdebuglevel(1)

That will enable debugging output, which among other things, will print out all the data it sends.

If you only want to get the headers and request line, not the request body (or any other debugging output), you can subclass HTTPConnection and override the _output method, which is called by the class itself to produce output (except for the request body). You'd want to do something like this:

class MyHTTPConnection(HTTPConnection):
    def _output(self, s):
        print repr(s)
        super(MyHTTPConnection, self)._output(s)

For more details on how that works and possible alternatives, have a look at the httplib source code.

David Zaslavsky