urllib POST question

John Taylor john_taylor_1973 at yahoo.com
Sat Jun 22 07:35:22 CEST 2002


rdacker at pacbell.net (rdack) wrote in message news:<644f6688.0206210900.68dd930c at posting.google.com>...
> Ben Beuchler <insyte-clp at emt-p.org> wrote in message news:<slrnah4dbq.r77.insyte-clp at petra.bitstream.net>...
> > In article <644f6688.0206200930.48110837 at posting.google.com>, rdack wrote:
> > > i am doing a POST to a server using urllib and it works.
> > > is there some way i can see exactly what is being posted?
> > > a way to get the post object out of urllib - the exact lines it is sending?
> > 
> > I'm a big fan of Ethereal...
> > "Sniffing the glue that holds the internet together!"
> > 
> > http://www.ethereal.com/
> 
> i am looking into it. seems overkill for wanting to see a few bytes
> that python is generating.
> No way within python to see what urllib intends to send out for the
> POST?

If you have the tcpdump program available (most likely on unix), then
you can use the script below.  The program is a wee bit on the slow
side
when processing large files, so any suggested speed ups would be
appreciated.

Also available at http://www.terry.uga.edu/~jft/ptd.py


#!/usr/bin/env python

# ptd - Print TcpDump
# John Taylor 2002-06-03

# Requires Python 2, will not work on Python 1.5.2

# Example:
# tcpdump -n -i eth0 -x -vv -t -s 4096 ip and not port 22 | ptd.py

import sys

# if set to 1, you will see a line count status on stderr
VERBOSE = 1
VERBOSE_PERIOD = 2000

#
# Main
#

def main():
        line_count = 0
        for line in sys.stdin.xreadlines():
                line_count += 1
                newline = " "
                hexdata = line.split("\t")
                if 4 == len(hexdata) :
                        hexline = hexdata[3].split()
                        for w in hexline:
                                h1 = w[:2]
                                h2 = w[2:]
                                if( len(h1) ):
                                        i = int("0x"+h1,16)
                                        if i >= 32 and i <= 127:
                                                newline += chr(i)
                                        else:
                                                if " " == newline[-1]
:
                                                        newline += "%s
" % (h1)
                                                else:
                                                        newline += "
%s " % (h1)

                                if( len(h2) ):
                                        i = int("0x"+h2,16)
                                        if i >= 32 and i <= 127:
                                                newline += chr(i)
                                        else:
                                                if " " == newline[-1]
:
                                                        newline += "%s
" % (h2)
                                                else:
                                                        newline += "
%s " % (h2)

                        print newline

                else:
                        one = line[0:1]
                        if " " == line[1:2] and (">" == one or "<" ==
one or "B" == one):
                                print
                        print line,

                if 1 == VERBOSE and (0 == line_count %
VERBOSE_PERIOD):
                        sys.stderr.write("%d\n" % line_count)

#
# Program execution begins here
#

main()



More information about the Python-list mailing list