名称错误:名称“pass_result”未定义第25行?

2024-05-23 18:27:17 发布

您现在位置:Python中文网/ 问答频道 /正文

在索引.html公司名称:

<html>
<head>
<title>Login Page</title>
<link type="text/css" rel="stylesheet" href="coach.css" />
</head>
<body>
<img src="images/logo-cel-transparent_0.png" width="74" height="64"><strong><img src="images/logo-cel-transparent_0.png" alt="Cel logo" width="74" height="64" align="right">
</strong>
<h1 align="center"><strong>Central Electronics Limited</strong></h1>
<p>&nbsp;</p>
<h2 align="center">Storage Management System</h2>
<p>&nbsp;</p>
<p align="center">Login To System</p>
<p align="center">&nbsp;</p>
<form action="cgi-bin/validate.py" method="post">
  <div align="center">Username :
    <input type="text" name="username">
    <br>
    Password :
    <input type="text" name="password">
    <br>
    <input type="submit" value="Submit">
  </div>
</form>
<p align="center">&nbsp;</p>
</body>
</html>

在验证.py公司名称:

^{pr2}$

在成功验证.py公司名称:

import yate


print(yate.start_response())

print(yate.para("Login Successful"))
print(yate.include_footer({"Click here to Go to Welcome Page":"/welcome.html"}))

简单_httpd.py公司(服务器代码):

from http.server import HTTPServer, CGIHTTPRequestHandler

port = 8080

httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
print("Starting simple_httpd on port: " + str(httpd.server_port))
httpd.serve_forever()

我运行服务器(简单_httpd.py公司)使用命令提示符。索引页打开。我输入第一组用户名和密码。它按预期运行并且成功验证.py打开。但是当我输入第二组用户名和密码时(即,第二行表validate in用户.sqlite)(validate表包含两组用户名和密码),它显示在cmd上:

127.0.0.1 - - [18/Jun/2015 20:59:29] b'Traceback (most recent call last):\r\n  F
ile "C:\\Python34\\ProjectShivam\\webapp\\cgi-bin\\validate.py", line 25, in <mo
dule>\r\n    password1=[row[0] for row in pass_result.fetchall()]\r\nNameError:
name \'pass_result\' is not defined\r\n'

另外,任何其他用户名都不会导致在web浏览器上打印“登录失败”文本,而是在服务器上显示相同的错误。怎么了?在


Tags: py名称porthtmltype公司validate用户名
1条回答
网友
1楼 · 发布于 2024-05-23 18:27:17

当不满足此条件时,您将收到错误:

if (username==each_username):
    pass_result=cursor.execute('SELECT PASSWORD from validate where username=?',(each_username,))

设置一个默认值来传递结果,例如pass_result = None,然后在使用之前处理它,例如if pass_result is not None:

相关问题 更多 >