2014-06-14 37 views
6

benim kodunda 404 HTTP hata yolunu test etmek istediğinizde aşağıdaki hatayı alıyorum: Ben bu davranışı tetikleyen minimal örneğini oluşturdukİçerik uzunlukta hatası

AssertionError: Content-Length is different from actual app_iter length (512!=60)

:

import unittest 
import endpoints 
from protorpc import remote 
from protorpc.message_types import VoidMessage 
import webtest 

@endpoints.api(name='test', version='v1') 
class HelloWorld(remote.Service): 
    @endpoints.method(VoidMessage, VoidMessage, 
         path='test_path', http_method='POST', 
         name='test_name') 
    def test(self, request): 
     raise endpoints.NotFoundException("Not found") 

class AppTest(unittest.TestCase): 
    def setUp(self): 
     app = endpoints.api_server([HelloWorld]) 
     self.testapp = webtest.TestApp(app) 

    # Test the handler. 
    def testHelloWorldHandler(self): 
     response = self.testapp.post('/_ah/spi/HelloWorld.test', extra_environ={ 
      'SERVER_SOFTWARE': 'Development/X', 'CONTENT_TYPE': 'application/json'}) 

Peki ne yapıyorum yanlış?

+0

çalışıyor olacak? Tahminimce ... – Veedrac

+0

Bende - sunucuda bir uç nokta istisnası oluşturduğunuzda olur. Bu http://trac.turbogears.org/ticket/2454'ü buldum, ancak yine de düzeltmedim - Ne zaman yaptığımı bileceğim :) –

cevap

9

Bu, App Engine ile bilinen bir hatadır.

https://code.google.com/p/googleappengine/issues/detail?id=10544

, bir diff dosya yukarıdaki bağlantıyı dahil olduğu düzeltmek veya geçici yama benim talimatları uygulayın: Bir istisna yükseltmek zaman

Endpoints doğru içerik-uzunluk başlığı belirlemez kendi kendine.

1. Bir mac üzerinde Açık apiserving.py

en dosyayı bulabilirsiniz:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/endpoints-1.0/endpoints 

2. Aşağıdaki bölümde bulun (hat 467):

Gelmeli Şunlara benzer:

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) 
01 Buna

3. Değişim it:

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. Her şey tamam!

Endpoints doğru İçerik Uzunluğu dönecektir, WebOb mutlu olacak ve tam hata mı API testleri :)

+0

https://code.google.com/p/ googleappengine/sorunlar/detay? id = 12533 ​​# c5 –

İlgili konular