【问题标题】:AWS API gateway Lambda autherizer warningAWS API 网关 Lambda 授权程序警告
【发布时间】:2020-03-20 09:53:55
【问题描述】:

AWS API Gateway Authorizer lambda 正在使用警告:

/var/runtime/botocore/vendored/requests/api.py:64:DeprecationWarning:您正在使用“botocore.vendored.requests”中的 post() 函数。此依赖项已从 Botocore 中删除,并将在 2020/03/31 之后从 Lambda 中删除。 https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/。安装requests包,直接'import requests',改用requests.post()函数。

我知道这可以通过导入 requests 包来解决,但是我尝试了使用 urllib3(boto3 中的默认包)是否可以解决它。下面是我的代码

data = {
    'token': access_token,
    'client_id': client_id,
    'client_secret': client_secret,
    'token_type_hint': 'access_token'
}
http = urllib3.PoolManager()

encoded_data = json.dumps(data).encode('utf-8')
introspection = http.request(method='POST',
                             url=INTROSPECTION_ENDPOINT,
                             body=encoded_data,
                             headers={'Content-Type': 'application/x-www-form-urlencoded'}
                             )

运行代码后出现以下错误: {"error_description":"自省端点需要token参数。","error":"invalid_request"}'

但使用请求也是如此

data = {
    'token': access_token,
    'client_id': client_id,
    'client_secret': client_secret,
    'token_type_hint': 'access_token'
}

introspection = requests.post(
     url=INTROSPECTION_ENDPOINT,
     data=data,
     headers={
         'Content-Type': 'application/x-www-form-urlencoded'
     }
 )

【问题讨论】:

    标签: python aws-lambda python-requests urllib3


    【解决方案1】:

    在尝试连接到 OAuth2 端点的 AWS Lambda 中遇到了完全相同的问题。我花了一些时间才弄明白,但您需要禁用默认启用的 encode_multipart。

    r = http.request_encode_body('POST', URL, fields=body, headers=headers, encode_multipart=False)
    

    【讨论】:

      【解决方案2】:

      使用请求库,因为我找不到明确的答案

      【讨论】:

        猜你喜欢
        • 2020-02-24
        • 2019-11-18
        • 2017-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-12
        • 2019-04-22
        • 2021-06-23
        相关资源
        最近更新 更多