【问题标题】:How to receive HTML form data in Python 3?如何在 Python 3 中接收 HTML 表单数据?
【发布时间】:2013-10-17 08:27:29
【问题描述】:

作为项目的一部分,我试图让 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 网络表单中获取 usernamepassword 变量?

【问题讨论】:

    标签: python html python-3.x


    【解决方案1】:

    只需在 CheckLogin.py 中获取这些值并将它们传递给login()

    import cgi
    # ...
    i = cgi.FieldStorage()
    username = i["htmlUser"]
    password = i["htmlPassword"]
    login(username, password)
    

    【讨论】:

      猜你喜欢
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 2017-11-16
      • 2013-06-09
      • 2022-07-07
      • 2019-03-30
      相关资源
      最近更新 更多