简体   繁体   English

代码中的AWS授权 - {“message”:“请求中包含的安全令牌无效。”}

[英]AWS Authorization In Code - {“message”: “The security token included in the request is invalid.” }

I am trying to invoke an API call in my Lambda function in the form of requests.get(url, auth=auth) . 我试图以requests.get(url, auth=auth)的形式在我的Lambda函数中调用API调用。

I have the url of the API endpoint but I am having issues with the authorization part of it. 我有API端点的url,但我遇到了授权部分的问题。 I imported an equivalent package of Requests-aws4auth and am getting my access key and secret key from Boto3 by following these instructions . 我导入了一个等效的Requests-aws4auth包,并按照这些说明从Boto3获取了我的访问密钥和密钥。

session = boto3.Session()
credentials = session.get_credentials()
credentials = credentials.get_frozen_credentials()
access_key = credentials.access_key
secret_key = credentials.secret_key
auth = AWS4AuthHandler(access_key=access_key, secret_key=secret_key, service_name='execute-api', region_name='us-west-2')
brand_info = requests.get(url, auth=auth).json()

However, brand_info returns: 但是,brand_info返回:

{"message": "The security token included in the request is invalid." }

I'm assuming this is an issue with my access and secret keys, and if that's the case, am I missing any steps to get the correct access / secret key? 我假设这是我的访问和密钥的问题,如果是这样的话,我是否缺少任何获取正确访问/密钥的步骤?

You need to obtain the security token also and pass it on. 您还需要获取安全令牌并将其传递。 You can obtain it as: 你可以获得它:

token = credentials.token

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用 GetSecretValue 操作时发生错误(UnrecognizedClientException):请求中包含的安全令牌无效 - An error occurred (UnrecognizedClientException) when calling the GetSecretValue operation: The security token included in the request is invalid 请求无效。 详细信息:参数:无效的 JSON。 在 JSON 内容中无法识别令牌 - The request is invalid. Details: parameters : Invalid JSON. A token was not recognized in the JSON content 在Google处使用访问令牌交换授权码:400错误请求 - Exchanging authorization code with access token @ Google: 400 Bad Request Flask OAuth 2.0 授权码流 使用 Fitbit 的授权令牌无效 API - Flask OAuth 2.0 Authorization Code Flow Invalid Authorization Token with Fitbit API Python请求无效消息 - Python request invalid message Python(请求库)ETL:Spotify API“授权代码流”-请求访问令牌问题 - Python (requests library) ETL: Spotify API "Authorization Code Flow" - Request Access Token Problem Boto MWS错误请求中的一个或多个参数值无效。 出现无效的ID - Boto MWS Error One or more parameter values in the request is invalid. Invalid ids presented Office 365 授权码请求 - Office 365 Authorization Code Request 使用 urllib2 时出现“无效的安全令牌” - "Invalid security token" while using urllib2 Spotify授权代码-获取令牌[控制台应用程序] - Spotify authorization code - get token [ console application ]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM