Cannot use Requests-Module on AWS Lambda

后端 未结 5 1478
故里飘歌
故里飘歌 2020-12-02 11:56

I need to do a rest-call within a python script, that runs once per day. I can\'t pack the \"requests\" package into my python-package using the AWS Lambdas. I get the error

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 12:35

    If you're working with Python on AWS Lambda, and need to use requests, you better use urllib3, it is currently supported on AWS Lambda and you can import it directly, check the example on urllib3 site.

    import urllib3
    
    http = urllib3.PoolManager()
    r = http.request('GET', 'http://httpbin.org/robots.txt')
    
    r.data
    # b'User-agent: *\nDisallow: /deny\n'
    r.status
    # 200
    

提交回复
热议问题