By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

Headers for Form Submision, and also HTTPrequests

P: n/a
I am currently working a program that was intended to be purely JS and
AJAX. Due to the cross domain access problems i have defaulted to a
language I enjoy more, Python. My project consists of a web service
that provides information from a site that can only be accessed through
a portal type system. The information is retrieved by a python script
then relayed to the web browser. This information is behind a simple
username and password type setup. The reason I am requesting help is
because I am currently in a ditch. The form submission part is very
simple in python and I have used it before. I never used it for logging
into a site though. This is where I ran into problems, I try to submit
a user name and password that I know are correct, but it does not work.
My only guess is that the headers, are incorrect and the site i am
trying to access has a security measure that prevents form submission
from anything other than a web browser. I tried multiple combinations
referring to the docs, but nothing seemed to work. It would submit but
return: "Invalid login", so it was posting to the site but probaly
posting the incorrect values. Here is a cut down version in html that
works just fine through a web browser for logining into the site:

method="post" name="theForm" id="theForm">
<input type="text" name="email" >
<input type="password" name="password" >
<input type="submit" value="Login"/>

And here is a stand alone version from python docs of the form
submision through python:

import httplib, urllib
params = urllib.urlencode({'email': '*****@***.***', 'password':
h = httplib.HTTP("")
h.putrequest("POST", "/index.cfm?fuseaction=login.process")
h.putheader("Content-length", "%d" % len(params))
h.putheader('Accept', 'text/plain')
h.putheader('Host', '')
reply, msg, hdrs = h.getreply()
print reply # should be 200
data = h.getfile().read() # get the raw HTML
print data

This code returns an invalid login even though the values are correct.
The only thing i can think of that there is something wrong with the
headers. Is there anyway to imitate a web browser if that is the
problem or some how figure out what the headers consist of that are
being submited and just copy that? and also is it possible once you are
logged in to this website to continue to a different page within the
member area, to extract more information? If anyone has any sugestions
on another way to go about doing this please let me know, and also i
already thought about using a mozilla/firefox plugin but i want to do
it in python :).


Jul 10 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
ev******* wrote:
method="post" name="theForm" id="theForm">
<input type="text" name="email" >
<input type="password" name="password" >
<input type="submit" value="Login"/>
What happens when you add the form param "submit" with value "Login"
to the request you're doing?
Perhaps the page needs this third parameter....

Jul 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.