2013-03-20 48 views
1

我使用gae和Python 2.7,升級到gae 1.7.6後,我的單元測試被破壞。我正在使用nose和nosega進行單元測試。有誰知道發生了什麼事?任何想法將非常感激。我覺得這與webob 1.2.3被升級到GA有關。升級到appengine後斷開連接錯誤1.7.6

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 &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py&quot;, line 1089, in __call__ 
    method(*args, **kwargs) 
    File &quot;/Users/***/projects/game_server/game_service/events.py&quot;, line 184, in post 
    inputs = pickle.loads(self.request.body) 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 677, in _body__get 
    self.make_body_seekable() # we need this to have content_length 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 922, in make_body_seekable 
    self.copy_body() 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 945, in copy_body 
    self.body = self.body_file.read(self.content_length) 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 1528, in readinto 
    + &quot;(%d more bytes were expected)&quot; % 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 &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py&quot;, line 1089, in __call__ 
    method(*args, **kwargs) 
    File &quot;/Users/***/projects/game_server/game_service/events.py&quot;, line 184, in post 
    inputs = pickle.loads(self.request.body) 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 677, in _body__get 
    self.make_body_seekable() # we need this to have content_length 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 922, in make_body_seekable 
    self.copy_body() 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 945, in copy_body 
    self.body = self.body_file.read(self.content_length) 
    File &quot;/Users/***/Downloads/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.2.3/webob/request.py&quot;, line 1528, in readinto 
    + &quot;(%d more bytes were expected)&quot; % self.remaining 
DisconnectionError: The client disconnected while sending the POST/PUT body (151 more bytes were expected) 
</pre> 

回答

1

簡短版本:headers可能包含錯誤的內容長度;修復它像這樣(假設paramsstr):

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改變了默認的WebOb從V0.9至V1.2.3。用於檢索請求參數的代碼(例如,通過webob.Request.get())在這些版本之間改變。

在1.2.3,如果你看一下BaseRequest.params它創建了一個NestedMultiDict使用BaseRequest.POST這反過來又嘗試讀取使用cgi.FieldStorage()它檢查Content-Length頭的請求的主體。如果內容長度不正確,您會看到您遇到的DisconnectionError

在0.9,Request.params使用Request.str_params構建,其使用Request.str_POST(不同於1.2.3)構建其NestedMultiDict。這反過來使用已有的Request.body_ file,其已經與StringIO()一起使用,沒有檢查內容長度報頭

因此,您可以在1.7.5中使用不正確的Content-Length標頭,但不在1.7.6中。

任務隊列數據是Base64編碼的。我懷疑你在回溯的第一行傳入的params已經從其Base64格式解碼,但是您沒有更新headers中的Content-Length標頭以反映這一點。我懷疑你從任務隊列上的GetTasks()獲得了任務的頭部,該任務隊列的Content-Length設置爲原始Base64編碼數據的長度。

0

您要發送的請求可能缺少適當的Content-Length標頭。

沒有它,服務器無法確定客戶端是否已上傳所有數據,或者他是否在傳輸過程中斷開連接。

+0

有趣的,不知道爲什麼發生這種情況,因爲請求是由WebTest準備的,並且只有在升級到appengine 1.7.6時纔會中斷。我已經瀏覽了webtest代碼,並且代碼設置了內容長度 – marcadian 2013-03-26 18:33:14

+1

我在1.7.6中遇到了很多問題。我回到了old_dev_appserver。 – Mohamed 2013-03-27 23:52:52

+1

是的,我現在也恢復到1.7.5 – marcadian 2013-03-28 19:50:33