【问题标题】:No module named 'requests' error for a Python Lambda in Cloud9 - I am not using requests at allCloud9 中的 Python Lambda 没有名为“请求”的模块错误 - 我根本没有使用请求
【发布时间】:2021-01-12 16:00:25
【问题描述】:

我正在 Cloud9 中编写 Python Lambda。 尝试运行它(在本地,在部署到后端之前),我收到了这个错误:

Invalid lambda response received: Invalid API Gateway Response Keys: {'errorType', 'errorMessage'} in {'errorMessage': "Unable to import module 'getPersonByKey': No module named 'requests'", 'errorType': 'Runtime.ImportModuleError'}

我没有在我的代码中使用请求,没有导入它,它不包含在 requirements.txt 文件中。

这是我的 Lambda 代码:

import json
import pyTigerGraphBeta as tg

def lambda_handler(event, context):
    try:
        conn = tg.TigerGraphConnection(host="https://skillblaster-dev.i.tgcloud.io", graphname="SkillBlasterDev", useCert=True)
        conn.apiToken = conn.getToken("rak++++++++++41f")[0]

        print("Calling to run installed query")
        result = conn.runInstalledQuery("getPersonByKey", {"keyPerson":"mor@excellench.com"})

    except Exception as e:
        print(e)    
        raise e

    return {
        "statusCode": 200,
        "body": json.dumps("TEST"),
    }

我错过了什么?

【问题讨论】:

    标签: python aws-lambda aws-cloud9


    【解决方案1】:

    pyTigerGraphBeta 库很可能在底层使用 requests 库。我多次遇到这个问题。

    解决方案 会将 requests 库添加到您的 requirements.txt(或您使用的任何包管理器 - 诗歌、pip、pipenv)中,因此它将最终出现在您的 lambda 所在的 zip 文件中代码是(您上传到 s3)。

    【讨论】:

    • @James 谢谢。将其添加到需求中没有任何作用。我尝试了 pip install - 说它已经满意了,它存在一个文件夹列表。我无权访问这些文件夹。想法?
    • @MorSagmon 在我的 requirements.txt 我有行 requests==2.24.0 并 pip 安装它。我觉得你是在全局安装它,而不是你应该拥有自己的 virtualenv 来包含你所有的包。请检查这个答案,它应该可以帮助你stackoverflow.com/questions/7225900/…
    猜你喜欢
    • 2018-04-10
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多