Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

python - Invalid Syntax in except handler when using comma

I am a beginner in Python and have been testing different kinds of sample code. When I started using Python3 instead of 2.7; I came upon a syntax error, but I don't understand how to fix that error.

  File "app.py", line 101
    except InvalidUserPass, e:
                          ^
SyntaxError: invalid syntax

Here is more of that code to give some context:

@app.route('/login/', methods=['GET', 'POST'])
def login():
    error = None
    if request.method == 'POST':
        session['username'] = request.form['username']
        session['password'] = request.form['password']
        try:
            # use reddit_api's login
            r.login(user=session['username'], password=session['password'])
        except InvalidUserPass, e:
            error = 'Incorrect username or password. '
        if not error:
            subreddits = r.user.get_my_reddits(limit=25)
            my_reddits = []
            for i in range(25):
                my_reddits.append(subreddits.next().display_name)
            session['my_reddits'] = my_reddits
            return redirect(url_for('index'))
    return render_template('login.html', error=error)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change

except InvalidUserPass, e:

to

except InvalidUserPass as e:

See this for more info.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...