user3671325
user3671325

Reputation: 336

How is exception syntax in python 3?

I'm using SMTP and SSH libs, it works all fine in Python 2.7, but there is a problem in Python3. examples:

try:
    server.login(user, passwd)
    flag = 0
except smtplib.SMTPException, err:

and

    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        if timeout_sec is not None:
            ssh.connect(target, username='', password='', timeout=timeout_sec)
        else:
            ssh.connect(target, username='', password='')
        exit = 0
        break
    except paramiko.ssh_exception.AuthenticationException, ssherr:

the exception examples are not working. How can I fix this?

    except paramiko.ssh_exception.AuthenticationException, ssherr:
                                                         ^
SyntaxError: invalid syntax

Upvotes: 0

Views: 630

Answers (1)

phd
phd

Reputation: 94827

except smtplib.SMTPException as err:

except paramiko.ssh_exception.AuthenticationException as ssherr:

See the docs at https://docs.python.org/3/reference/compound_stmts.html#the-try-statement

Upvotes: 2

Related Questions