Question about urllib and posting to an external script

Discussion in 'Python' started by evanpmeth@gmail.com, Sep 6, 2006.

  1. Guest

    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' : '',
    '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' :
    '', '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).
     
    , Sep 6, 2006
    #1
    1. Advertising

  2. alex23 Guest

    wrote:
    > 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
     
    alex23, Sep 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alanb
    Replies:
    2
    Views:
    575
    alanb
    Apr 23, 2004
  2. AmitKu
    Replies:
    7
    Views:
    582
    John Timney \(MVP\)
    Jan 8, 2007
  3. Jonathan Gardner

    Asynchronous urllib (urllib+asyncore)?

    Jonathan Gardner, Feb 26, 2008, in forum: Python
    Replies:
    1
    Views:
    502
    Terry Jones
    Feb 27, 2008
  4. Chris McDonald
    Replies:
    0
    Views:
    326
    Chris McDonald
    Nov 1, 2010
  5. Mellow Crow
    Replies:
    6
    Views:
    438
    Richard Cornford
    Nov 4, 2005
Loading...

Share This Page