Headers for Form Submision, and also HTTPrequests

2006-07-09 Thread evanpmeth
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:

http://login.myspace.com/index.cfm?fuseaction=login.process";
method="post" name="theForm" id="theForm">




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

import httplib, urllib
params = urllib.urlencode({'email': '[EMAIL PROTECTED]', 'password':
'*'})
h = httplib.HTTP("login.myspace.com:80")
h.putrequest("POST", "/index.cfm?fuseaction=login.process")
h.putheader("Content-length", "%d" % len(params))
h.putheader('Accept', 'text/plain')
h.putheader('Host', 'www.myspace.com')
h.endheaders()
h.send(params)
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 :).

-EvanPMeth

-- 
http://mail.python.org/mailman/listinfo/python-list


Question about urllib and posting to an external script

2006-09-05 Thread evanpmeth
I have tried multiple ways of posting information to a website and have
failed. I have seen this problem on other forums can someone explain or
point me to information on how POST works through urllib an different
broweser (what is the difference).

my first attempt was out of the docs:

Code:

import httplib, urllib params = urllib.urlencode({'email' : '[EMAIL PROTECTED]',
'password' : 'pass'}) h = httplib.HTTP("login.myspace.com:80")
h.putrequest("POST", "/index.cfm?fuseaction=login.process&")
h.putheader("User-Agent", "Mozilla/5.0  Gecko/20060728 Firefox/1.5.0.6")
h.putheader("Content-length", "%d" % len(params)) h.putheader('Accept',
'text/plain') h.endheaders() h.send(params) reply, msg, hdrs =
h.getreply() print reply # should be 200 data = h.getfile().read() #
get the raw HTML print data



this returned a page denying access
and then tried:

Code:

import httplib, urllib params = urllib.urlencode({'email' :
'[EMAIL PROTECTED]', 'password' : 'dicksuck'})
data
=urllib.urlopen("http://login.myspace.com/index.cfm?fuseaction=login.process&:80";,
params).read()
print data



This returned a page that asked me if i wanted to sign up, which
confused me even more.

all i want to do is post this form:
HTML Code:


  



Please help i was thinking maybe the site did browser sniffing and only
allowed certain types of browsers. I dont know. I have seen this
problem on other forums can someone explain or point me to information
on how POST works through urllib an different broweser (what is the
difference).

-- 
http://mail.python.org/mailman/listinfo/python-list