basic web auth and verification

Discussion in 'Python' started by scripteaze@gmail.com, Oct 23, 2007.

  1. Guest

    Trying to figure out how to add login verfication. I believe it is
    logging me in, but theres no way to really tell..any ideas? or
    tutorials out there that can exaplain this to me?

    Thanks

    import urllib,urllib2,cookielib

    passlst = open(passfile, 'r').readlines()
    url="http://somesite"
    cj = cookielib.LWPCookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)
    TheForm = urllib.urlencode({"username":"myid","password":"mypas"})
    request = urllib2.Request(url, TheForm)
    result = urllib2.urlopen(request)
    html=result.read()
    result.close()
    , Oct 23, 2007
    #1
    1. Advertising

  2. schrieb:
    > Trying to figure out how to add login verfication. I believe it is
    > logging me in, but theres no way to really tell..any ideas? or
    > tutorials out there that can exaplain this to me?
    >
    > Thanks
    >
    > import urllib,urllib2,cookielib
    >
    > passlst = open(passfile, 'r').readlines()
    > url="http://somesite"
    > cj = cookielib.LWPCookieJar()
    > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    > urllib2.install_opener(opener)
    > TheForm = urllib.urlencode({"username":"myid","password":"mypas"})
    > request = urllib2.Request(url, TheForm)
    > result = urllib2.urlopen(request)
    > html=result.read()
    > result.close()
    >


    I had the same trouble. There was a redirect after login a had to
    follow. Look at the following code.

    def login(self):
    ''' Log into web site. '''

    self._br.set_handle_redirect(True)
    cj = CookieJar()
    self._br.set_cookiejar(cj)
    self._br.open(Config.urlLogin)
    self._br.select_form(name='login')

    self._br['session_key'] = Config.username
    self._br['session_password'] = Config.password
    response=self._br.submit()
    self._br.set_response(response)
    for link in self._br.links(url_regex="www.somesite.com"):
    self._br.follow_link(link)
    if 'Sign In' in self._br.title():
    raise ValueError('Wrong password')


    Regards,
    Ralf Schoenian
    =?ISO-8859-1?Q?Ralf_Sch=F6nian?=, Oct 23, 2007
    #2
    1. Advertising

  3. Guest

    On Oct 23, 12:55 am, Ralf Schönian <> wrote:
    > schrieb:
    >
    >
    >
    >
    >
    > > Trying to figure out how to add login verfication. I believe it is
    > > logging me in, but theres no way to really tell..any ideas? or
    > > tutorials out there that can exaplain this to me?

    >
    > > Thanks

    >
    > > import urllib,urllib2,cookielib

    >
    > > passlst = open(passfile, 'r').readlines()
    > > url="http://somesite"
    > > cj = cookielib.LWPCookieJar()
    > > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    > > urllib2.install_opener(opener)
    > > TheForm = urllib.urlencode({"username":"myid","password":"mypas"})
    > > request = urllib2.Request(url, TheForm)
    > > result = urllib2.urlopen(request)
    > > html=result.read()
    > > result.close()

    >
    > I had the same trouble. There was a redirect after login a had to
    > follow. Look at the following code.
    >
    > def login(self):
    > ''' Log into web site. '''
    >
    > self._br.set_handle_redirect(True)
    > cj = CookieJar()
    > self._br.set_cookiejar(cj)
    > self._br.open(Config.urlLogin)
    > self._br.select_form(name='login')
    >
    > self._br['session_key'] = Config.username
    > self._br['session_password'] = Config.password
    > response=self._br.submit()
    > self._br.set_response(response)
    > for link in self._br.links(url_regex="www.somesite.com"):
    > self._br.follow_link(link)
    > if 'Sign In' in self._br.title():
    > raise ValueError('Wrong password')
    >
    > Regards,
    > Ralf Schoenian- Hide quoted text -
    >
    > - Show quoted text -


    Thank you very much, ill look into it..
    , Oct 24, 2007
    #3
    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. =?Utf-8?B?Q2hyaXMgTW9oYW4=?=

    Configuring Windows Auth & Forms Auth in Asp.Net

    =?Utf-8?B?Q2hyaXMgTW9oYW4=?=, Apr 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    687
    =?Utf-8?B?Q2hyaXMgTW9oYW4=?=
    Apr 28, 2004
  2. =?Utf-8?B?ZGhucml2ZXJzaWRl?=

    Windows Auth, but Forms Auth for one page?

    =?Utf-8?B?ZGhucml2ZXJzaWRl?=, Jan 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    543
    Elton Wang
    Jan 8, 2005
  3. Mark Chai
    Replies:
    1
    Views:
    738
    Christophe Vanfleteren
    Oct 1, 2003
  4. Chris Mohan

    Configuring Windows Auth & Forms Auth in Asp.Net

    Chris Mohan, Apr 28, 2004, in forum: ASP .Net Security
    Replies:
    2
    Views:
    406
    Chris Mohan
    Apr 29, 2004
  5. cs

    Form Auth and windows int auth

    cs, Apr 18, 2006, in forum: ASP .Net Security
    Replies:
    1
    Views:
    112
    Timothy H. Schilbach
    Apr 28, 2006
Loading...

Share This Page