Simulating WWW button press

C.Laurence Gonsalves clgonsal at keeshah.penguinpowered.com
Tue Jan 2 01:36:40 EST 2001


On 2 Jan 2001 01:49:15 GMT, Lutz Schroeer
<Lutz.Schroeer at tu-clausthal.de> wrote:
>
>Well, maybe this snippet of the (very unreadable) source is large
>enough.
>
><form ACTION="/dyx-pv/onepagebatch/lV21.zip" ENCTYPE=x-www-form-encoded
>METHOD=POST>
>
><INPUT NAME="zipallpage" TYPE="submit" VALUE="Get all files"> </form>
>
>I tried and read some more stuff and ended at the example 11.3.2 in the
>Library reference (1.5.2). Unfortunately my own version of this code
>doesn't work (it stucks after the getfile() ). 
>
>Is my suggestion right that the base address for the submission is the
>same as the page's base address if the code defines nothing different? 
>
>Additionally I came to the conclusion that I seem to have to send a
>Content-Length header entry (the server replied me an error 411) but
>have no idea about the value.
>
>To make it totally complicated the form is on a password protected
>page.  So how do I send my username and passwd to the server? 


You'll want to include an "Authorization:" line in your HTTP headers.
eg:

Authorization: Basic dXNlcmlkOnBhc3N3b3Jk

The junk after "Basic" is the userid and password encoded in base64. You
can generate this by doing something like:

    import string, base64

    # need to use strip, because base64.encodestring adds a trailing
    # '\r' that we don't want
    auth = string.strip(base64.encodestring(userid+':'+password))
    

Incidently, you might want to test if this server works with HTTP GET
requests. If you aren't sending many parameters to it (and from the
looks of the HTML above, you aren't), there isn't really any point in
using POST, unless the server requires it. Most CGI programs don't
actually care which way they get the parameters.

-- 
  C. Laurence Gonsalves                "Any sufficiently advanced
  clgonsal at kami.com                     technology is indistinguishable
  http://cryogen.com/clgonsal/          from magic." -- Arthur C. Clarke



More information about the Python-list mailing list