Login with python - megaupload
Question: I'm trying to fix a program which can login to my MU account and retrieve some
data....

I don't know what am I doing wrong....That's the code:

    
    
    #!/usr/bin/env python
    import urllib, urllib2, cookielib
    
    username = 'username'
    password = 'password'
    
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    login_data = urllib.urlencode({'username' : username, 'password' : password})
    opener.open('http://megaupload.com/index.php?c=login', login_data)
    resp = opener.open('http://www.megaupload.com/index.php?c=filemanager')
    print resp.read()
    

Thx for any answer!


Answer: You can simulate the filling of the form.

For that you can use [mechanize
lib](http://wwwsearch.sourceforge.net/mechanize/) base on perl module
WWW::Mechanize.

    
    
    #!/usr/bin/env python
    import urllib, urllib2, cookielib, mechanize
    
    username = 'username'
    password = 'password'
    
    br = mechanize.Browser()
    cj = cookielib.CookieJar()
    
    br.set_cookiejar(cj)
    br.set_handle_robots(False)
    
    br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6')]
    
    br.open('http://www.megaupload.com/?c=login')
    br.select_form('loginfrm')
    
    br.form['username'] = username
    br.form['password'] = password
    
    br.submit()
    
    resp = br.open('http://www.megaupload.com/index.php?c=filemanager')
    
    print resp.read()
    

See [Use mechanize to log into
megaupload](http://stackoverflow.com/questions/4422389/use-mechanize-to-log-
into-megaupload)

