【发布时间】: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