我使用Python 2.7,在升级到gae 1.7.6之后,我的单元测试被破坏了。我正在使用鼻子和鼻子进行单元测试。有谁知道发生了什么事?任何想法都会非常感激。我觉得这与webob 1.2.3被提升为GA有关。
self.app.post(task['url'], params, headers)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 835, in post
content_type=content_type)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 807, in _gen_request
expect_errors=expect_errors)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 1118, in do_request
self._check_status(status, res)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 1154, in _check_status
res)
AppError: Bad response: 500 Internal Server Error (not 200 OK or 3xx redirect for http://localhost/task/request_log)
<pre>Traceback (most recent call last):
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1089, in __call__
method(*args, **kwargs)
File "/Users/***/projects/game_server/game_service/events.py", line 184, in post
inputs = pickle.loads(self.request.body)
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 677, in _body__get
self.make_body_seekable() # we need this to have content_length
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 922, in make_body_seekable
self.copy_body()
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 945, in copy_body
self.body = self.body_file.read(self.content_length)
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 1528, in readinto
+ "(%d more bytes were expected)" % self.remaining
DisconnectionError: The client disconnected while sending the POST/PUT body (151 more bytes were expected)
</pre>
self.app.post(task['url'], params, headers)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 835, in post
content_type=content_type)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 807, in _gen_request
expect_errors=expect_errors)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 1118, in do_request
self._check_status(status, res)
File "/Library/Python/2.7/site-packages/WebTest-1.4.0-py2.7.egg/webtest/app.py", line 1154, in _check_status
res)
AppError: Bad response: 500 Internal Server Error (not 200 OK or 3xx redirect for http://localhost/task/request_log)
<pre>Traceback (most recent call last):
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1089, in __call__
method(*args, **kwargs)
File "/Users/***/projects/game_server/game_service/events.py", line 184, in post
inputs = pickle.loads(self.request.body)
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 677, in _body__get
self.make_body_seekable() # we need this to have content_length
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 922, in make_body_seekable
self.copy_body()
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 945, in copy_body
self.body = self.body_file.read(self.content_length)
File "/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py", line 1528, in readinto
+ "(%d more bytes were expected)" % self.remaining
DisconnectionError: The client disconnected while sending the POST/PUT body (151 more bytes were expected)
</pre>
答案 0 :(得分:1)
简短版本: headers
可能包含不正确的内容长度;像这样修复它(假设params
是str
):
fixed_header = ('Content-Length', str(len(params)))
for i, header in enumerate(headers):
if header[0] == 'Content-Length':
headers[i] = fixed_header
fixed_header = None
break
if fixed_header: # in case you're completely missing a Content-Length header
headers.append(fixed_header)
GAE 1.7.6将默认网络从v0.9更改为v1.2.3。用于检索请求参数的代码(例如,通过webob.Request.get()
)在这些版本之间改变。
在1.2.3中,如果您查看BaseRequest.params
,则会使用NestedMultiDict
创建BaseRequest.POST
,cgi.FieldStorage()
会使用DisconnectionError
检查请求的正文Content-Length标头。如果内容长度不正确,您将获得您遇到的Request.params
。
在0.9中,Request.str_params
是使用NestedMultiDict
构建的,Request.str_POST
使用Request.body_ file
(不同于1.2.3)构建其StringIO()
。这反过来使用预先存在的params
,它与headers
一起使用,而不检查Content-Length标题。
因此,您可以在1.7.5中使用不正确的Content-Length标头,但不能在1.7.6中使用。
任务队列数据是Base64编码的。我怀疑您在追溯的第一行传入的GetTasks()
已经从其Base64格式解码,但您没有更新{{1}}中的Content-Length标头以反映这一点。我怀疑你从任务队列存根{{1}}获得了任务的头文件,其任务队列存根的内容长度设置为原始Base64编码数据的长度。
答案 1 :(得分:0)
您发送的请求可能缺少正确的Content-Length标头。
如果没有它,服务器无法确切地确定客户端是否已上传所有数据,或者他是否在传输过程中断开连接。