0

プロジェクトの一環として、Python に HTML で送信されたフォームを受信させようとしています。変数を取得したら、コンソールに「True」または「False」を出力するためにpythonが必要です。これがフォームの現在の 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 Web フォームから変数usernameと変数を取得させることができますか?password

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 に答える