我有一个用于 AWS Lambda 函数的 Python 脚本,该函数向另一个端点发出 HTTP POST 请求。自从Python的urllib2.request
, https://docs.python.org/2/library/urllib2.html https://docs.python.org/2/library/urllib2.html,只能处理标准中的数据application/x-www-form-urlencoded
格式并且我想发布 JSON 数据,我使用了 Requests 库,https://pypi.org/project/requests/2.7.0/ https://pypi.org/project/requests/2.7.0/.
该 Requests 库在 Python 运行时环境中的 AWS Lambda 上不可用,因此必须通过以下方式导入from botocore.vendored import requests
。到目前为止,一切都很好。
今天,我收到了关于此的弃用警告:
DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'.
This is not a public API in botocore and will be removed in the future.
Additionally, this version of requests is out of date. We recommend you install the
requests package, 'import requests' directly, and use the requests.post() function instead.
AWS 的这篇博文中也提到了这一点:https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/ https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/.
不幸的是,改变from botocore.vendored import requests
into import requests
结果出现以下错误:
No module named 'requests'
Why is requests
不适用于 AWS Lambda 上的 Python 运行时?我该如何使用/导入它?