0

As part of a project, I am trying to have python receive a form sent by HTML. Upon getting the variables, I need python to print either "True" or "False" in the console. Here is my current HTML code for the form.

...
<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>
...

Once I have had them submit their username and password, I want to use this data to check if they can log into an email server (I have used Google's in this case, Microsoft Server 2003 doesn't play nicely.) Here is my Python 3 script to do so:

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)

My question is, how can I have python get the username and password variables from the HTML webform?

4

1 回答 1

0

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

import cgi
# ...
i = cgi.FieldStorage()
username = i["htmlUser"]
password = i["htmlPassword"]
login(username, password)
于 2013-10-17T00:27:29.413 回答