Python 为什么environ[';QUERY#u STRING';]返回零长度字符串?

Python 为什么environ[';QUERY#u STRING';]返回零长度字符串?,python,ajax,apache,client-server,Python,Ajax,Apache,Client Server,我找到了我(愚蠢)问题的解决方案,并将其列在下面 我正在Ubuntu 11.04上使用Python 2.7.1+。客户端/服务器位于同一台计算机上 通过Wing调试器,我知道正在调用服务器代码,我可以一次遍历一行代码。在本例中,我知道传输了22个字节 在Firebug中,我在Net Post选项卡下看到了以下数据: Parameter application/x-www-form-urlencoded fname first lname last Source Content-Typ

我找到了我(愚蠢)问题的解决方案,并将其列在下面

我正在Ubuntu 11.04上使用Python 2.7.1+。客户端/服务器位于同一台计算机上

通过Wing调试器,我知道正在调用服务器代码,我可以一次遍历一行代码。在本例中,我知道传输了22个字节

在Firebug中,我在Net Post选项卡下看到了以下数据:

Parameter   application/x-www-form-urlencoded
fname   first
lname   last
Source
Content-Type: application/x-www-form-urlencoded
Content-Length: 22 fname=first&lname=last
这是我正在使用的客户端代码:

<html>
     <form action="addGraphNotes.wsgi" method="post">
         First name: <input type="text" name="fname" /><br />
         Last name: <input type="text" name="lname" /><br />
         <input type="submit" value="Submit" />
    </form>
</html>
在Wing调试器中,我验证了数据是否正在从客户端传递到服务器:

>>> environ['wsgi.input'].read()
'fname=first&lname=last'
发现了我的问题。我复制并粘贴了错误的代码。这是我用于表单的代码,但当我开始使用AJAX并停止使用表单时,请停止添加它。现在,一切正常。

# When the method is POST the query string will be sent
# in the HTTP request body which is passed by the WSGI server
# in the file like wsgi.input environment variable.
request_body = environ['wsgi.input'].read(request_body_size)

values = parse_qs(request_body) 

您正在执行
POST
查询,因此
query\u字符串实际上是空的,因为它表示
GET
请求的查询字符串(它也可以出现在其他请求类型中,但与当前问题无关)。您应该通过使用
wsgi.input
流来解析
POST
数据。

您是否尝试打印出整个
环境
dict?有关其他详细信息,请参阅编辑的问题。我尝试了“获取”,但没有改变任何内容。我之前编写的所有其他表单/提交代码都使用了“post”,代码运行良好。这台机器上好像有什么东西坏了,我弄不清是什么东西。我一直在用post提交表单,一切都很好。直到我开始使用这台电脑。
# When the method is POST the query string will be sent
# in the HTTP request body which is passed by the WSGI server
# in the file like wsgi.input environment variable.
request_body = environ['wsgi.input'].read(request_body_size)

values = parse_qs(request_body)