Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

No module named 'requests' error for a Python Lambda in Cloud9 - I am not using requests at all

I am writing a Python Lambda in Cloud9. Trying to run it (locally, before deploying to the backend), I'm receiving this error:

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'}

I am NOT using requests in my code, not importing it, it is not included in the requirements.txt file.

This is my Lambda code:

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":"[email protected]"})

    except Exception as e:
        print(e)    
        raise e

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

What am I missing?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Most likely the pyTigerGraphBeta lib uses requests library under the hood. I faced this issue couple of times.

The Solution would be adding requests library to your requirements.txt (or whatever package manager you use - poetry, pip, pipenv) so it will end up in the zip file where your lambda code is (that you upload to s3).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...