gpt4 book ai didi

python - 谷歌应用引擎: Response "Content-Length" header is always 0

转载 作者:行者123 更新时间:2023-12-01 05:44:26 25 4
gpt4 key购买 nike

我按照 Google App Engine 教程进行操作,但在向留言簿类中的响应对象添加内容时遇到了一些问题。

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 重定向的响应代码和告诉浏览器重定向到何处的 Location: header 。

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

关于python - 谷歌应用引擎: Response "Content-Length" header is always 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16600135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com