Invalid Syntax in except handler when using comma

Solution 1:

Change

except InvalidUserPass, e:

to

except InvalidUserPass as e:

See this for more info.

Solution 2:

Simply except InvalidUserPass as e:. And for heaven's sake, let's get rid of the ugly error thing:

@app.route('/login/', methods=['GET', 'POST'])
def login():
    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 as e:
            return render_template('login.html', 
                                   error='Incorrect username or password.')

        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')

Solution 3:

In python3 it's:

except InvalidUserPass as e: