Problem with httplib and POST
Ray Van Dolson
leovd at pacbell.net
Wed Nov 7 13:54:10 EST 2001
I'm writing a kind of interface to the Dotster.com website that will allow
me to automatically update my DNS entries (controlled via a web interface
on their server) when my IP changes by calling a Python script. So far
I've made pretty good progress. In case you're interested, the location
of my source is currently at:
http://www.bludgeon.org/cvs/index.cgi/pydotster/
On to my problem. Once I do all the authentication and stuff, I receive
two cookies from the server--a session ID and a cookie setting the domain
I am currently working with. Then I can call the editdns form and POST a
new IP to it. This is where I am running into problems. Here is an
excerpt of the HTML of the form I'm trying to complete:
<form METHOD=POST Action=editdns.asp?Update=1&sld_nsrec_id=4444 id=form1
name=form1>
<table border="0" width="70%">
<tr> <CENTER><STRONG><STRONG> EDIT RECORD FOR BLUDGEON.ORG</CENTER>
</STRONG></STRONG><td width='32%'><b>Host Name</b></td><td width='14%'
align=center><b>Record</b></td><td width='24%'><b>Host IP
Address</b></td></tr><tr><td width='32%' >
<input type=text size=30 name=hostname value=TRISTRAM.BLUDGEON.ORG><td
width='14%' align= center>ALIAS</td><td width='24%'>
<input type=text name=hostip value=127.0.0.1 size=20></td>
</tr>
</table>
<p>
<input type="submit" value="Update DNS Record" name="B1"></p>
</form>
Basically I am doing something like this to process this form:
h = httplib.HTTPS('www.dotster.com')
h.putrequest("POST", "/management/editdns.asp?Update=1&sld_nsrec_id=4444")
h.putheader('Accept', 'text/html')
h.putheader('Content-type', 'application/x-www-form-urlencoded')
h.putheader('Host', 'www.dotster.com')
h.putheader('Cookie', 'Domain=Name=BLUDGEON%2EORG;
path=/ASPSESSIONIDQQQQQWUG=JCNNMKIAEEJABDOPNCCEGFFA; path=/')
params = urllib.urlencode({'hostname': HOST_HERE, 'hostip': NEW_IP, 'B1':
'Update DNS Record'})
h.putheader('Content-Length', "%d" % len(params))
h.endheaders()
h.send(params)
reply, msg, headers = h.getreply()
Is there anything glaringly wrong with this that doesn't match up with the
FORM above? This executes just fine and I get a redirect from the server
(302) however, the new IP is NOT accepted. The old one is still there.
I'm scratching my head trying to figure out what I am not sending to the
server. Does order of Cookies matter? The whole POST line that I am
sending seems a little strange to me since it actually has parameters on
it... Could it be perhaps that I am using HTTP/1.0 instead of HTTP/1.1?
If so, how can I make httplib use HTTP/1.1? I edited the httplib.py and
changed the string from 1.0 to 1.1, but that caused my script to hang.
I normally run a sniffer to try and figure out exactly what headers my web
browser sends when it does this exacct same thing (successfully), however
since this is an SSL-only site, this doesn't exactly work. :) I saved the
form do my own server and processed it locally and watched the headers.
Of course, the cookies weren't set for my local site (I can't recreate
their authentication scheme) but I was able to duplicate the headers
exactly in my script. Still no go.
Any advice?
Ray Van Dolson
More information about the Python-list
mailing list