Question about urllib and posting to an external script

E

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' : '(e-mail address removed)',
'password' : 'pass'}) h = httplib.HTTP("login.myspace.com:80")
h.putrequest("POST", "/index.cfm?fuseaction=login.process&amp")
h.putheader("User-Agent", "Mozilla/5.0 <Windows; U; Windows NT 5.1;
en-US; rv;1.8.0.6> 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' :
'(e-mail address removed)', 'password' : 'dicksuck'})
data
=urllib.urlopen("http://login.myspace.com/index.cfm?fuseaction=login.process&amp: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:

<form method='POST' enctype='multipart/form-data'
action='http://login.myspace.com/index.cfm?fuseaction=login.process&amp'>
<input type="text" name="email" > <input type="password"
name="password" > <input type="submit" value="Login"/>



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).
 
A

alex23

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

<form method='POST' enctype='multipart/form-data'
action='http://login.myspace.com/index.cfm?fuseaction=login.process&amp'>
<input type="text" name="email" > <input type="password"
name="password" > <input type="submit" value="Login"/>

Heya,

It might help to use one of the higher-level abstractions for dealing
with the web. twill (http://twill.idyll.org/) provides a simple
language for scripting web-based interactions.

The example they provide should be useable as a basis for what you
want:
++++
setlocal username <your username>
setlocal password <your password>

go http://www.slashdot.org/
formvalue 1 unickname $username
formvalue 1 upasswd $password
submit

code 200 # make sure form submission is correct!
++++

I _think_ twill is based on top of mechanize
(http://wwwsearch.sourceforge.net/mechanize/) which may be of use to
you if twill obscures or hides functionality you need.

Hope this helps.

-alex23
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top