更新时间:2023-01-15 12:12:47
这是App Engine的一个已知错误.
This is a known error with App Engine.
引发异常时,端点没有设置正确的Content-Length标头:
Endpoints does not set the correct Content-Length header when you raise an exception:
https://code.google.com/p/googleappengine/issues/detail?id = 10544
要修复此问题,上面的链接中包含一个diff
文件,或者按照我的指示由您自己临时对其进行修补.
To fix it there is a diff
file included in the link above, or follow my instructions to temporarily patch it by yourself.
1.打开apiserving.py
1. Open apiserving.py
在Mac上,您可以在以下位置找到文件:
On a mac you can find the file at:
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/endpoints-1.0/endpoints
2.找到以下部分(第467行):
它应该看起来像这样:
headers_dict = dict([(k.lower(), v) for k, v in headers])
if self.__is_json_error(status, headers_dict):
status, body = self.protorpc_to_endpoints_error(status, body)
3.更改为此:
headers_dict = dict([(k.lower(), v) for k, v in headers])
if self.__is_json_error(status, headers_dict):
pre_body_length = len(body)
status, body = self.protorpc_to_endpoints_error(status, body)
post_body_length = len(body)
if pre_body_length != post_body_length:
for index, header in enumerate(headers):
header_key, _header_value = header
if header_key == 'content-length':
headers[index] = (header_key, str(post_body_length))
break
4.全部完成!
端点将返回正确的Content-Length,WebOb将很高兴,并且您的API测试将正常进行:)
Endpoints will return the correct Content-Length, WebOb will be happy and your API tests will be working :)