Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > basic web auth and verification

Reply
Thread Tools

basic web auth and verification

 
 
scripteaze@gmail.com
Guest
Posts: n/a
 
      10-23-2007
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(c j))
urllib2.install_opener(opener)
TheForm = urllib.urlencode({"username":"myid","password":"my pas"})
request = urllib2.Request(url, TheForm)
result = urllib2.urlopen(request)
html=result.read()
result.close()

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Ralf_Sch=F6nian?=
Guest
Posts: n/a
 
      10-23-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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(c j))
> urllib2.install_opener(opener)
> TheForm = urllib.urlencode({"username":"myid","password":"my pas"})
> 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
 
Reply With Quote
 
 
 
 
scripteaze@gmail.com
Guest
Posts: n/a
 
      10-24-2007
On Oct 23, 12:55 am, Ralf Schönian <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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(c j))
> > urllib2.install_opener(opener)
> > TheForm = urllib.urlencode({"username":"myid","password":"my pas"})
> > 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..

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
windows auth and forms auth Smokey Grindle ASP .Net 1 06-08-2006 03:14 PM
Form Auth and windows int auth cs ASP .Net Security 1 04-28-2006 03:05 PM
Windows Auth, but Forms Auth for one page? =?Utf-8?B?ZGhucml2ZXJzaWRl?= ASP .Net 1 01-08-2005 05:50 PM
Configuring Windows Auth & Forms Auth in Asp.Net =?Utf-8?B?Q2hyaXMgTW9oYW4=?= ASP .Net 0 04-28-2004 06:11 PM
container-auth vs servlet-auth role-checking? Mark Chai Java 1 10-01-2003 06:30 PM



Advertisments