作为项目的一部分,我试图让python接收HTML发送的表单。获取变量后,我需要python在控制台中打印“True”或“False”。这是我目前的表单HTML代码。
...
<form name = "input" action = "CheckLogin.py" method = "get">
<!-- This is the form. Here the user submits their username and password.
The words before the colon are the words that appear on the user's screen -->
Username: <input type = "text" name = "htmlUser">
<br>
Password: <input type = "password" name = "htmlPassword">
<input type = "submit" value = "Submit">
<br>
</form>
...
一旦我让他们提交了用户名和密码,我想使用这些数据来检查他们是否可以登录到电子邮件服务器(我在这种情况下使用了Google,但是Microsoft Server 2003不能很好地播放。)是我的Python 3脚本:
def login(username, password):
import poplib
try:
server = poplib.POP3_SSL('pop.gmail.com', 995)#Weird bug here. When I use the exeter server, I am informed that the SSL number is incorrect. How do I fix?
server.user(username)
server.pass_(password)
print ("True")
except:
print("False")
login (username, password)
我的问题是,如何让python从HTML webform获取username
和password
变量?
答案 0 :(得分:0)
只需在CheckLogin.py中获取这些值并将其传递给login()
:
import cgi
# ...
i = cgi.FieldStorage()
username = i["htmlUser"]
password = i["htmlPassword"]
login(username, password)