Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 谷歌应用程序引擎:响应“;内容长度“;标题始终为0_Python_Google App Engine_Response_Webapp2_Http Content Length - Fatal编程技术网

Python 谷歌应用程序引擎:响应“;内容长度“;标题始终为0

Python 谷歌应用程序引擎:响应“;内容长度“;标题始终为0,python,google-app-engine,response,webapp2,http-content-length,Python,Google App Engine,Response,Webapp2,Http Content Length,我学习了GoogleAppEngine教程,在guestbook类中向响应对象添加内容时遇到了一些问题 class Guestbook(webapp2.RequestHandler): def post(self): # We set the same parent key on the 'Greeting' to ensure each greeting # is in the same entity group. Queries across the single ent

我学习了GoogleAppEngine教程,在guestbook类中向响应对象添加内容时遇到了一些问题

class Guestbook(webapp2.RequestHandler):
def post(self):

    # We set the same  parent key on the 'Greeting' to ensure each greeting
    # is in the same entity group. Queries across the single entity group
    # will be consistent. However, the write rate to a single entity group
    # should be limited to ~1/second.
    guestbook_name = self.request.get('guestbook_name',
                                      DEFAULT_GUESTBOOK_NAME)
    testvar = self.request.get('testvar',
                                      DEFAULT_GUESTBOOK_NAME)
    greeting = Greeting(parent=guestbook_key(guestbook_name))

    if users.get_current_user():
        greeting.author = users.get_current_user()

    greeting.content = self.request.get('content')
    greeting.info = 'DIDTHISWORK?'
    greeting.put()

    self.response.headers.add_header("Expires", 'Information here')      
    #self.response.set_status(200,'Is this working?!')

    self.response.headers['Content-Type'] = 'text/plain'
    #self.response.headers['Content-Length'] = '5'
    self.response.out.write('Hello')


    query_params = {'guestbook_name': guestbook_name}
    self.redirect('/?' + urllib.urlencode(query_params))
    print type(self.response)
以下是使用Wireshark的响应数据包:

HTTP/1.1 302 Found
Cache-Control: no-cache
Expires: Information here
Content-Type: text/plain
Location: http://_______.appspot.com/?guestbook_name=default_guestbook
Date: Fri, 17 May 2013 01:21:52 GMT
Server: Google Frontend
Content-Length: 0

正如你所看到的,我试图用“Hello”填充内容体,但它一直给我content length=0,手动设置似乎没有帮助,所以我把它注释掉了。我认为您可以安全地忽略带有问候语的代码,但我在其中添加了它,以防它影响我所做的任何事情。

您在将任何内容打印到页面之前发送重定向,因此长度为0

self.redirect('/?' + urllib.urlencode(query_params)) # redirects
print type(self.response)                            # never executes
如果查看Wireshark捕获,请查看响应代码(302重定向)和
位置:
标题(告诉浏览器重定向到哪里)

HTTP/1.1 302 Found 
Location: http://_______.appspot.com/?guestbook_name=default_guestbook