login to https (newbie)

Discussion in 'Python' started by bkamrani@gmail.com, Jan 16, 2008.

  1. Guest

    Hi Python gurus!
    Please help me how I can login to this page:

    https://www.boplats.se/user/login_hs.aspx?ReturnUrl=/HSS/Default.aspx

    I tried these two codes, but I don't seem to be successfull at all.
    (Both gave same result.)
    Many many thanks,
    /Ben


    -----------
    import urllib2,urllib,cookielib
    urll = "https://www.boplats.se/user/login_hs.aspx?ReturnUrl=/HSS/
    Default.aspx"
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(cj))
    data = urllib.urlencode ( { "username" : "myuser" ,
    "password" :"mypass" } )
    fp = opener.open( urll,data )
    print fp.read()
    ------------
    OR th second code
    ------------
    import urllib2 as __urllib2
    import base64 as __base64
    #--------------------------------------------------------------
    def download_file(url, webuser = None, webpass = None):
    request = __urllib2.Request(url)

    if webuser:
    base64string = __base64.encodestring('%s:%s' % (webuser,
    webpass))[:-1]
    request.add_header("Authorization", "Basic %s" % base64string)

    htmlFile = __urllib2.urlopen(request)
    htmlData = htmlFile.read()
    htmlFile.close()

    return htmlData
    #--------------------------------------------------------------
    if __name__ == "__main__":
    # Test
    #*****************************
    __url = "https://www.boplats.se/user/login_hs.aspx?ReturnUrl=/HSS/
    Default.aspx"
    __webuser = "myuser"
    __webpass = "mypass"
    print download_file(__url, __webuser, __webpass)
    #*****************************
     
    , Jan 16, 2008
    #1
    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. Stimp

    using HTTPS for a login page

    Stimp, Aug 23, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    2,846
  2. Alfredo Barrientos
    Replies:
    0
    Views:
    524
    Alfredo Barrientos
    Aug 31, 2005
  3. Axel
    Replies:
    8
    Views:
    1,113
    Adrienne Boswell
    Apr 27, 2009
  4. jotto
    Replies:
    4
    Views:
    402
    jotto
    Oct 2, 2006
  5. Naveen Dhanuka
    Replies:
    1
    Views:
    292
Loading...

Share This Page