无论我做什么,即使没有识别码,我也总是收到缩进错误

问题描述

无论我做什么,我都无法弄清楚这一点。无论间距如何,我都会不断收到意外缩进错误。我花了两天时间自己修复它,并找到可以解释发生情况的人。我包括了CS50 IDE的屏幕截图,因为我觉得它最好地显示了我遇到的错误。

original error

@app.route("/sell",methods=["GET","POST"])
@login_required
def sell():

   if request.method == "POST":

       quote=lookup(request.form.get("symbol"))

       if quote == None:
           return apology ("invalid symbol",400)


        try:
            shares=int(request.form.get("shares"))
        except:
            return apology("shares must be positive",400)

updated error

解决方法

您需要使用try“关闭” except块,即:

try:
    shares=(int(request.form.get("shares"))
except Exception as err:
    print(err)

或跳过try,并使用try-except,当您知道预期的错误类型时,即:

shares=(int(request.form.get("shares"))

有关tr除外块here

的更多信息

所以关于缩进的错误也是令人误解的,(:

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...