AWS API 网关 Python-EVE "where" 在已部署 API 中不工作

AWS API Gateway with Python-EVE "where" not working in deployed API

我有一个Python-evepublicAPI,我们可以这样查询:

https://my-api.com/collections?where={"name":"peter"}

我想创建一个 API 网关来代理同一个 URL 端点,方法是:

https://my-api-amazon-gateway.com/prod/collections?where={"name":"peter"}

我做了什么:

  1. 我创建了一个新的 API 网关,其中包含一个新资源 "collections",以及一个用于此资源的 "GET" 方法。
  2. collections-GET-方法执行中,在方法请求中:
    • URL Query String Parameters,我加了一个name为"where"
    • HTTP 请求 Headers 中,我添加一个名称为 "Content-Type"
  3. 在"collections - GET - Method Execution",在"Integration Request"
    • URL 查询字符串参数 我有名字 "where" 并且映射自 "method.request.querystring.where"
    • HTTP Headers 中,我添加了一项 "Content-Type" 并映射自 "method.request.header.Content-Type"

如果我转到 方法测试 ,我将 {"name":"peter"} 作为 where Query Strings,并且 application/json 作为 Header content-type,一切都很好。

如果我部署 API 并在部署的 API 中尝试相同的端点,它不起作用:

https://my-api-amazon-gateway.com/prod/collections?where={"name":"peter"}

它 returns 一个错误 400 错误请求。 CloudWatch 中未记录任何内容。

如果我尝试击中

https://my-api-amazon-gateway.com/prod/collections?where=test

然后一切正常,我得到 HTTP 200 OK,但出现 Python-eve 错误 The browser (or proxy) sent a request that this server could not understand. 这与如果我尝试点击

的结果相同

https://my-api.com/collections?where=test

因此,由于我不知道的原因,测试有效,但部署的 API 网关在查询字符串为 object.

时不起作用

有什么线索吗?

非常感谢!

您将需要URL 对参数进行编码。它在通过 Method Test 进行测试时起作用的原因是因为它负责对参数进行编码。

而不是, https://my-api-amazon-gateway.com/prod/collections?where={"name":"peter"}

尝试一下, https://my-api-amazon-gateway.com/prod/collections?where=%7B%22name%22%3A%22peter%22%7D

希望对您有所帮助