AWS API Gateway Autherizer lambda is working with warning:
/var/runtime/botocore/vendored/requests/api.py:64: DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'. This dependency was removed from Botocore and will be removed from Lambda after 2020/03/31. https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/ . Install the requests package, 'import requests' directly, and use the requests.post() function instead.
I know this can be solved by importing requests package, but I tried if I could solve it using urllib3(default package in boto3). Below is my code
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'}
)
after running the code I am getting the following error: {"error_description":"token parameter is required for the introspection endpoint.","error":"invalid_request"}'
but the same is working using requests
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'
}
)
Had exactly the same issue in AWS Lambda trying to connect to an OAuth2 endpoint. Took me a while to figure it out, but you need to disable the encode_multipart which is enabled by default.
r = http.request_encode_body('POST', URL, fields=body, headers=headers, encode_multipart=False)
使用请求库,因为我找不到明确的答案
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.