【问题标题】:AWS API Gateway with Python-EVE "where" not working in deployed API带有 Python-EVE “where”的 AWS API Gateway 在部署的 API 中不起作用
【发布时间】:2016-08-14 16:25:13
【问题描述】:

我有一个Python-eve公共API,我们可以顺便查询一下:

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

我想创建一个 API 网关来代理同一个 URL 端点,顺便说一句:

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

我做了什么:

  1. 我创建了一个新的 API 网关,其中包含一个新的资源“集合”和该资源的“GET”方法。
  2. collections - GET - Method Execution 中,在 Method Request 中:
    • URL查询字符串参数中,我添加了一个名称为“where”的
    • HTTP 请求标头中,我添加了一个名为“Content-Type”的标头
  3. 在“集合 - GET - 方法执行”中,在“集成请求”中
    • URL 查询字符串参数中我有名称“where”并映射自“method.request.querystring.where”
    • HTTP Headers 中,我添加了一项“Content-Type”,其映射来自“method.request.header.Content-Type”

如果我去方法测试,我把{"name":"peter"}作为查询字符串application/json作为标题内容类型,一切都很好。

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

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

它返回一个错误400 Bad Request。 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 网关无法正常工作。

有什么线索吗?

非常感谢!

【问题讨论】:

    标签: api amazon-web-services aws-api-gateway eve


    【解决方案1】:

    您需要对参数进行 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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-01
      • 2016-12-23
      • 1970-01-01
      • 2018-11-12
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 2017-06-12
      相关资源
      最近更新 更多