Python Can';无法获取POST参数

Python Can';无法获取POST参数,python,http,post,parameters,webapp2,Python,Http,Post,Parameters,Webapp2,我正在用Python开发一个web应用程序,使用WebApp2作为框架。 我无法通过填写表单获取提交的http POST请求参数 这是我创建的表单的HTML代码 <html> <head> <title>Normal Login Page </title> </head> <body> <form method="post" action="/loginN/" enctype="text/plain" > eMa

我正在用Python开发一个web应用程序,使用WebApp2作为框架。 我无法通过填写表单获取提交的http POST请求参数

这是我创建的表单的HTML代码

<html>
<head>
<title>Normal Login Page </title>
</head>
<body>
<form method="post" action="/loginN/" enctype="text/plain" >
eMail: <input type="text" name="eMail"><br/>
password: <input type="text" name="pwd"><br/>
<input type="submit">
</form>
</body>
这是POST请求处理程序的代码

class loginN(BaseHandler):
    def post(self):
        w = self.response.write
        self.response.headers['Content-Type'] = 'text/html'
        logging.info(self.request)
        logging.info(self.request.POST.get('eMail'))
        logging.info(self.request.POST.get('pwd'))
        email = self.request.POST.get('eMail')
        pwd = self.request.POST.get('pwd')
        w('<html>')
        w('<head>')
        w('<title>Data Page </title>')
        w('</head>')
        w('<p>Welcome! Your mail is: %s</p>' % email)
        w('<p>Your pwd is: %s</p>' % pwd)
        w('</body>')  
类登录(BaseHandler):
def post(自我):
w=self.response.write
self.response.headers['Content-Type']='text/html'
logging.info(self.request)
logging.info(self.request.POST.get('eMail'))
logging.info(self.request.POST.get('pwd'))
email=self.request.POST.get('email')
pwd=self.request.POST.get('pwd')
w(“”)
w(“”)
w('数据页')
w(“”)
w(“欢迎!您的邮件是:%s

%”电子邮件) w(“您的pwd是:%s

”%pwd) w(“”)
BaseHandler是webapp2.RequestHandler,它是为处理会话而扩展的(我也尝试了webapp2.RequestHandler,得到了相同的结果)

我每次得到的两个参数都是“无”


关于如何解决这个问题有什么建议吗?我也尝试了self.request.get,而不是self.request.POST.get,但它也不起作用(我也没有得到任何结果)

尝试从表单中删除
enctype=“text/plain”
属性,然后使用
self.request.POST.get('eMail')
self.request.POST.get('pwd')

编辑:删除
enctype=“text/plain”
之所以有效,是因为您希望enctype为
“text/html”
(默认设置),以便webapp2将表单作为html表单读取。当它刚刚设置为
“text/plain”
时,表单的输出仅作为文本包含在请求正文中,这就是您打印请求时看到的内容。如果使用
“text/plain”
,则可以使用以下命令以字符串形式访问表单的输出:

form_string = str(self.request.body)
然后您可以解析该字符串以获得键值对。不过,正如您已经知道的那样,只需将enctype设置为html就可以更轻松地获得标准的http表单功能


我在文档中找不到明确的
enctype
信息,但是如果您对请求对象有其他问题,我建议您阅读关于请求对象的信息。Webapp2使用Webob请求,因此文档是理解您的请求obejct的地方。

它在没有enctype=“text/plain”的情况下工作。谢谢!你能解释一下为什么吗?我很高兴它成功了!我给我的答案加了一个解释。非常好!非常感谢。
form_string = str(self.request.body)