【问题标题】:AppError: Bad response: 404 Not Found (not 200 OKAppError:错误响应:404 Not Found(不是 200 OK
【发布时间】:2015-11-25 05:25:44
【问题描述】:

我在测试 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

【问题讨论】:

    标签: google-app-engine nosetests webtest


    【解决方案1】:

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

    要指示另一个状态,请使用关键字参数 status=404 以(例如)检查它是否为 404 状态,或 status="*" 允许任何状态,或者 status="400 Custom Bad Request" 允许 使用自定义原因短语。 如果您希望打印错误,请使用 expect_errors=True。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-10
      • 2010-09-25
      • 2015-07-26
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-24
      相关资源
      最近更新 更多