using exceptions

Peter Hansen peter at engcorp.com
Mon May 20 13:10:44 EDT 2002


Locke wrote:
> 
> I am trying to to some CGI using the poplib module. I want it to tell me if
> the password is incorrect. What is the exception I should use?
> 
>    23     try:
>    24         pop.pass_(password)
>    25     except error_proto:
>    26         print "Your password is incorrect."

You've already got it above, but you might be getting caught because
you did something like "from poplib import POP".  Or you just forgot
that you need to preface the item with the name of the module it was
defined in:

import poplib
pop = poplib.POP3("myserver")
pop.user('locke')
try:
    pop.pass_('badpwd')
except poplib.error_proto:
    print 'Authentication failed'

Something like that should work...

-Peter



More information about the Python-list mailing list