AppError: Bad response: 404 Not Found (not 200 OK

AppError: Bad response: 404 Not Found (not 200 OK

我在测试 API 时遇到以下错误。

AppError: Bad response: 404 Not Found (not 200 OK or 3xx redirect for http://localhost/_ah/spi/AdminAuthentication.authenticate)
'{"state": "APPLICATION_ERROR", "error_message": "No user with the E-mail address \"foo@bar.com\" exists."}'

这里是测试函数,我写的

def test_should_not_authenticate_if_there_is_no_user_for_email(self):
    app = endpoints.api_server([AdminAuthentication], restricted=False)
    testapp = webtest.TestApp(app)
    msg = {'email': 'foo@bar.com'}
    resp = testapp.post_json('/_ah/spi/AdminAuthentication.authenticate', msg)
    self.assertEqual(resp.status_int, 404)

app.yaml 文件的相应路由定义应如下所示,

- url: /_ah/spi/.*
  script: api.services.application

默认情况下,它需要状态代码 200。 http://webtest.readthedocs.org/en/latest/testapp.html

To indicate another status is expected, use the keyword argument status=404 to (for example) check that it is a 404 status, or status="*" to allow any status, or status="400 Custom Bad Request" to use custom reason phrase. If you expect errors to be printed, use expect_errors=True.