FAQ
I am sending a HTTP POST by using the following codes:

opener = urllib2.build_opener(proxyHandler, MultipartPostHandler)
params = { "audio" : "http://sample.com/my.wav",
"data" : open(file, "rb") }
print opener.open(myURL, params).read()

How do I log or print out the actual POST message (including headers)
that is sent out?
How do I log or print out the response headers as well?

Thanks

Search Discussions

  • Diez B. Roggisch at Jul 22, 2009 at 8:54 pm

    scriptlearner at gmail.com schrieb:
    I am sending a HTTP POST by using the following codes:

    opener = urllib2.build_opener(proxyHandler, MultipartPostHandler)
    params = { "audio" : "http://sample.com/my.wav",
    "data" : open(file, "rb") }
    print opener.open(myURL, params).read()

    How do I log or print out the actual POST message (including headers)
    that is sent out?
    How do I log or print out the response headers as well?
    You can use proxy-tools such as tcpmon or sniff traffic using wireshark.

    Diez
  • Scriptlearner at Jul 22, 2009 at 9:18 pm

    On Jul 22, 1:54?pm, "Diez B. Roggisch" wrote:
    You can use proxy-tools such as tcpmon or sniff traffic using wireshark.

    Diez
    Thanks,
    but I am trying to enable some debug mode to log all outgoing and
    incoming messages for certain period of time, and running another
    proxy-tool is not very ideal. It would be great to log it in some log
    file.
  • Gabriel Genellina at Jul 23, 2009 at 4:27 am
    En Wed, 22 Jul 2009 18:18:37 -0300, scriptlearner at gmail.com
    <scriptlearner at gmail.com> escribi?:
    On Jul 22, 1:54?pm, "Diez B. Roggisch" wrote:
    You can use proxy-tools such as tcpmon or sniff traffic using wireshark.
    Thanks,
    but I am trying to enable some debug mode to log all outgoing and
    incoming messages for certain period of time, and running another
    proxy-tool is not very ideal. It would be great to log it in some log
    file.
    You may install a custom HTTPHandler:

    class LoggingHTTPConnection(httplib.HTTPConnection):

    def request(self, method, url, body=None, headers={}):
    print method, url, headers
    httplib.HTTPConnection.request(self, method, url, body, headers)

    def getresponse(self):
    response = httplib.HTTPConnection.getresponse(self)
    print response.status, response.msg
    return response

    class LoggingHTTPHandler(urllib2.HTTPHandler):
    def http_open(self, req):
    return self.do_open(LoggingHTTPConnection, req)

    opener = urllib2.build_opener(LoggingHTTPHandler, ...)

    --
    Gabriel Genellina

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 22, '09 at 8:51p
activeJul 23, '09 at 4:27a
posts4
users3
websitepython.org

People

Translate

site design / logo © 2021 Grokbase