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

问题描述

无论我做什么,我都无法弄清楚这一点。无论间距如何,我都会不断收到意外缩进错误。我花了两天时间自己修复它,并找到可以解释发生情况的人。我包括了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

的更多信息

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...