Problems login in to a website in python
Question: I've been trying to connect python with http/https sites and I came across
urllib and urllib2. After some research I could create a website login but it
seems that I'm doing something wrong, I tried with different webpages but I
can't do it with any. There is the code I've been working on:

    
    
    import urllib, urllib2, cookielib
    
    #guardar cookies
    cookies = cookielib.CookieJar()
    
    #crear opener
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies))
    
    user = raw_input("Introdueix el teu nom d'usuari: ")
    contra = raw_input("Introdueix la teva pass: ")
    
    login_data = urllib.urlencode({'login' : user,'password' : contra})
    sessio = opener.open('http://streamcloud.eu/login.html', login_data)
    
    #en teoria ja esta logejat a partir d'aqui
    
    print "La URL accedida es:",sessio.geturl()
    
    #tanquem la web
    sessio.close()
    

The form of the website is this one:

    
    
    <form method="POST" action="http://streamcloud.eu/" class="proform" name="FL">
    <input type="hidden" name="op" value="login">
    <input type="hidden" name="redirect" value="http://streamcloud.eu/?op=upload">
    
    <p>
        <label>Username:</label>
        <input type="text" style="font-style: normal;" name="login" value="deuseux" class="text_field" />
    </p>
    <div class="clear"></div>
    <p>
        <label>Password:</label>
        <input type="password" style="font-style: normal;" name="password" class="text_field" />
    </p>
    <div class="clear"></div>
    <div>
        <input type="submit" class="button blue medium" value="Submit">
    </div>
    <div class="clear"></div>
    

The login form is in this webpage: <http://streamcloud.eu/login.html> while
the action of the form is in <http://streamcloud.eu>, maybe there's where I'm
doing something wrong? If I put a print sessio.read() I can clearly see that
I'm not logged in

Does anyone see something wrong with the code? Thanks!

ps: sorry for my bad english


Answer: Your English is fine :)

There are 2 other hidden input fields on the form which look like they need to
be submitted with your login and password. These are:

    
    
    <input type="hidden" name="op" value="login">
    <input type="hidden" name="redirect" value="http://streamcloud.eu/?op=upload">
    

I'd guess that `op=login` is required, not sure about the `redirect=...` \-
maybe you don't need that. Anyway, try changing your data to the following and
see if you get any further:

    
    
    login_data = urllib.urlencode({'login' : user, 'password' : contra, 'op' : 'login', 'redirect' : 'http://streamcloud.eu/?op=upload'})
    

