I am new to dealing with this so I am sorry if these are dumb questions.
How do you know if python was successful when logging into a website.
for now I am using stock code in their guides, so for example.
say i run this with my gmail information, and nothing happens, does that mean it succeeded. Or does the page need a pop up authentication?Code:import urllib2 import sys import re import base64 from urlparse import urlparse theurl = 'http://www.someserver.com/somepath/somepage.html' # if you want to run this example you'll need to supply # a protected page with your username and password username = 'johnny' password = 'XXXXXX' req = urllib2.Request(theurl) try: handle = urllib2.urlopen(req) except IOError, e: pass else: if not hasattr(e, 'code') or e.code != 401: authline = e.headers['www-authenticate'] authobj = re.compile( r'''(?:\s*www-authenticate\s*:)?\s*(\w*)\s+realm=['"]([^'"]+)['"]''', re.IGNORECASE) if not matchobj: print 'The authentication header is badly formed.' print authline sys.exit(1) scheme = matchobj.group(1) realm = matchobj.group(2) if scheme.lower() != 'basic': print 'This example only works with BASIC authentication.' sys.exit(1) base64string = base64.encodestring( '%s:%s' % (username, password))[:-1] authheader = "Basic %s" % base64string req.add_header("Authorization", authheader) try: handle = urllib2.urlopen(req) except IOError, e: print "It looks like the username or password is wrong." sys.exit(1) thepage = handle.read()
Thank you for any input.
Results 1 to 6 of 6
Thread: Question about python
- 04 Feb. 2010 12:49am #1
Question about python
- 04 Feb. 2010 01:18am #2
Seems like you're trying to login with the wrong protocol. This script is used to those pages that pop-up a text box asking you for username and password, and if you close the box it re-directs you to another page. I don't have a page for that example, however I have my own HTTP class I can post. It's pretty simple and easy to learn from.
- 04 Feb. 2010 01:21am #3
yeah I assumed what I was looking at was for pop up login but I havent seen one of those in forever so was wondering.
I would love to see the http class.
Python seems very interesting, the little I have looked at seems fairly easy to use, and the guides you can find online and in its own guide section are fairly useful.
thanks for the response man
- 04 Feb. 2010 01:25am #4
Logicalgamers - Powered by vBulletin
One of these? ;o
- 04 Feb. 2010 01:26am #5
- 04 Feb. 2010 01:33am #6
http://forum.logicalgamers.com/sourc...tml#post105169
Should work for you. Run the script and you;ll see Google's source returned into the interpreter.