Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python尝试,但最后出现无效语法错误_Python_Exception_Flask_Finally - Fatal编程技术网

Python尝试,但最后出现无效语法错误

Python尝试,但最后出现无效语法错误,python,exception,flask,finally,Python,Exception,Flask,Finally,所以我尝试在python中使用这个异常处理。我用的是python2.7和烧瓶。另外,我对python和flask都是新手,所以我一定是做错了什么 if test: cursor = conn.cursor() try: print cursor.execute("INSERT INTO Users (email, password, firstname, lastname, home, gender, dob, bio, profile_Image) VALUES

所以我尝试在python中使用这个异常处理。我用的是python2.7和烧瓶。另外,我对python和flask都是新手,所以我一定是做错了什么

if test:
    cursor = conn.cursor()
    try:
        print cursor.execute("INSERT INTO Users (email, password, firstname, lastname, home, gender, dob, bio, profile_Image) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}')".format(email, password, firstname, lastname, home, gender, dob, bio, photo_data))
        conn.commit()
        #log user in
        user = User()
        user.id = email
        flask_login.login_user(user)
        uid = getUserIdFromEmail(flask_login.current_user.id)
        today = str(date.today())
        print today
    except Exception as e:
        print e
        print "Something Went wrong"
        return flask.redirect(flask.url_for('register'))
    print cursor.execute("INSERT INTO Album (uid, aname, adate, cover) VALUES ('{0}', 'default', '{1}', '{2}')".format(uid, today, photo_data))
    aid = getAIDfromAname('default', uid)
    cursor.execute("INSERT INTO Photo (uid, aid, data, caption) VALUES ('{0}', '{1}', '{2}', 'profile')".format(uid,aid,photo_data))
    cursor.execute("INSERT INTO Scoreboard (uid) VALUES ('{0}')".format(uid))
    conn.commit()
    finally:
        cursor.close()
    return render_template('profile.html', firstname=firstname, message='Account Created!')

else:
    print "couldn't find all tokens"
    return render_template('register.html', message='Email Already Exists')
如果我运行应用程序,它会给我这个错误

  File "app.py", line 540
finally:
      ^SyntaxError: invalid syntax
我想知道为什么它会给我错误:/

if test:
    cursor = conn.cursor()
    try:
        print cursor.execute("INSERT INTO Users (email, password, firstname, 
lastname, home, gender, dob, bio, profile_Image) VALUES ('{0}', '{1}', '{2}', 
'{3}', '{4}', '{5}', '{6}', '{7}', '{8}')".format(email, password, firstname, 
lastname, home, gender, dob, bio, photo_data))
        conn.commit()
        #log user in
        user = User()
        user.id = email
        flask_login.login_user(user)
        uid = getUserIdFromEmail(flask_login.current_user.id)
        today = str(date.today())
        print today
    except Exception as e:
        print e
        print "Something Went wrong"
        print cursor.execute("INSERT INTO Album (uid, aname, adate, cover) VALUES ('{0}', 'default', '{1}', '{2}')".format(uid, today, photo_data))
        aid = getAIDfromAname('default', uid)
        cursor.execute("INSERT INTO Photo (uid, aid, data, caption) VALUES ('{0}', '{1}', '{2}', 'profile')".format(uid,aid,photo_data))
        cursor.execute("INSERT INTO Scoreboard (uid) VALUES ('{0}')".format(uid))
        conn.commit()
        return flask.redirect(flask.url_for('register'))
    finally:
        cursor.close()
    return render_template('profile.html', firstname=firstname, message='Account 
Created!'))

else:
    print "couldn't find all tokens"
    return render_template('register.html', message='Email Already Exists'
这会奏效的。块内“print cursor.execute”行上的缩进不正确


这会奏效的。块内“print cursor.execute”行上的缩进不正确。

缩进已关闭。try/exept块在其下方的凸出打印结束。缩进已关闭。try/exept块在其下方的凸出打印结束。expection块中
return
语句之后的代码将永远不会执行。谢谢。新手犯的错误。编辑代码。很抱歉,我必须已经查看了整个代码。Expection块中
return
语句后面的代码将永远不会执行。谢谢。新手犯的错误。编辑代码。对不起,我一定已经看过全部代码了。