On Sat, Sep 11, 2010 at 01:28:26AM +0200, Evert Rol wrote: > > My script to call a web service authenticates. > Sorry, but where is the (full) script? I missed an attachment or (preferably) > a link.
Hello, Sorry, the verb of the sentence is "authenticates," as in, "My script ... authenticates." But I can show the authentication portion. 8<-------------- start -------------------->8 # Creates an authentication object with the credentials for a given URL def createPasswordManager(headers) : passwordManager = urllib2.HTTPPasswordMgrWithDefaultRealm() passwordManager.add_password(None,overview_url,headers[0],headers[1]) return passwordManager # Creates an authentication handler for the authentication object created above def createAuthenticationHandler(passwordManager) : authenticationHandler = urllib2.HTTPBasicAuthHandler(passwordManager) return authenticationHandler # Creates an opener that sets the credentials in the Request def createOpener(authHandler) : return urllib2.build_opener(authHandler) # Retrieves the data def getData(authHeaders) : opener = createOpener(createAuthenticationHandler(createPasswordManager(authHeaders))) data = opener.open(overview_url) return data 8<--------------- end ------------------------>8 So, to restate the question, how can I trap an exception in the cases in which authentication fails? Right now, the whole script is complete and working (thanks for your help with my other exception-handling question). Except for the case of bad credentials. The use case is that the user misspells a username or password or puts in a wrong account information. Then, I don't want them to sit for 10 minutes while the script makes 30 data connections, retries and fails each time. Thanks. mp -- Michael Powe mich...@trollope.org Naugatuck CT USA I hate a fellow whom pride, or cowardice, or laziness drives into a corner, and who does nothing when he is there but sit and <growl>; let him come out as I do, and <bark>. -- Samuel Johnson
pgpaSYEIaSF3p.pgp
Description: PGP signature
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor