如何修复 AttributeError:模块 'botocore.vendored.requests' 没有属性 'Post' Traceback

Jos*_*se' 7 amazon-web-services python-3.x aws-lambda

我正在尝试让我的 LexBot 与 Lambda 进行通信,因此我遵循了创建请求、签名以及执行此操作所需的一切的过程。但我不确定是否需要从 Python 导入某些东西。当我要发布消息时它失败了。创建签名以及 auth 标头。

请大家指教,任何帮助将不胜感激!

我使用这些文章作为指导:https : //docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html

https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

print ('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
print ('Request URL = ' + endpoint)
print('\n' + authorization_header)
print('\nX-Amz-content-Sha256 header is' + payload_hash)

r = requests.Post ('myendpoint'+ canonical_uri, data=payload, 
headers=headers)
data = r.json()
lex_message = data['message']
print ('' + lex_message)
Run Code Online (Sandbox Code Playgroud)

所以我假设我的问题来自这段代码,注意我删除了我的端点。

也不确定请求中的数据是什么。

Mar*_*cin 10

我有同样的错误,但GET使用python3.8. GET对/的支持POST已从botocore.vendored.requests中删除python3.8

作为解决方法,您可以使用python3.7lambda,它仍然可以工作一段时间。然而,您会收到一个警告,即对此的支持2020/03/31也将被删除:

DeprecationWarning: You are using the put() 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.put() function instead.
Run Code Online (Sandbox Code Playgroud)

因此,没有太多选择来使用pip获取requests包或使用层,如下面的链接所示。

更多信息可以在 AWS Lambda 中的 Python SDK 即将发生的更改中找到