Devarshi Goswami
Devarshi Goswami

Reputation: 1225

AWS lambda throwing import error because of URLLIB

Im running a python script on aws lambda and its throwing the following error.

 {
   "errorMessage": "Unable to import module 'app': urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with OpenSSL 1.0.2k-fips  26 Jan 2017. See: https://github.com/urllib3/urllib3/issues/2168",
   "errorType": "Runtime.ImportModuleError",
   "stackTrace": [] }

It was running perfectly an hour ago , and even after I have made no deployments , it seems to be failing.

my python version is 3.7. and Im only using urllib to parse and unquote urls . namely

from urllib.parse import urlparse

and

from urllib.parse import unquote

like its mentioned in the GitHub url I can upgrade my python version, but doing so would break other things. Are there any alternative librries I can use to get the same result?

from the GitHub link , it shows urllib no longer supports OpenSSL<1.1.1 but somehow some of our higher environments the same scripts is running without issues.

Upvotes: 11

Views: 23238

Answers (11)

Anitha Nehru
Anitha Nehru

Reputation: 1

In my lambda, I have updated the python version to the latest. And it worked perfectly.

Upvotes: 0

Pedro
Pedro

Reputation: 489

If you look at the GH issue in the error message, you'll see that the problem only occurs to Python >=3.7 but <3.10

upgrade to python 3.10 and problem solved

Upvotes: 1

Mugdhap
Mugdhap

Reputation: 21

I was able to resolve this issue using an older version of the urllib library when I was installing all the other libraries required by my code:

python -m pip install urllib3==1.26.16 --no-deps -t 

Upvotes: 2

rabkaman
rabkaman

Reputation: 131

I hacked at this quite a bit and ended up doing a few things.

I'm using python 3.8.16

  1. I installed the openssl11

    sudo yum install openssl11
    
  2. found the existing runtime.

whereis openssl
openssl: /usr/bin/openssl /usr/lib64/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz
  1. renamed the old openssl

    sudo mv openssl openssl102
    
  2. symlinked the new version

    ln -s openssl11 openssl
    
  3. in the appropriate build directory, i then rebuilt the target python modules under the supported version.

    python3 -m pip install --target . urllib3==1.26.15
    

Upvotes: 0

Ramalinga Reddy
Ramalinga Reddy

Reputation: 1

I have been facing this issue, what worked for me is that I have installed urllib version 1.26.16 locally and made zip out of it, then added this zip in layers. I have used this in combination with openai and it worked since we are adding dependencies in layers.

pip install openai urllib3==1.26.16

Upvotes: 0

Sharhabeel Hamdan
Sharhabeel Hamdan

Reputation: 1549

Upgrade you AWS Lambda function runtime to Python 3.10 and it should work.

Upvotes: 5

Freek Wiekmeijer
Freek Wiekmeijer

Reputation: 4940

I encountered this because of the following pip requrement in my Pipenv file:

requests = ">= 2.28.2, < 3"

What went wrong:

  • requests depends on urllib3
  • this dependency changed in requests 2.30.
    • requests/setup.py v2.29.0: "urllib3>=1.21.1,<1.27"
    • requests/setup.py v2.30.0: "urllib3>=1.21.1,<3"

Effectively the minor version upgrade of reguests 2.29 to 2.30 caused a major version upgrade of urllib3 version 1.x to 2.x. Which is backward incompatile and required a newer OpenSSL library on the system.

My simple fix was to change my requests dependency to

requests = ">= 2.28.2, < 2.29.0"

There will be similar errors with other pip dependencies which depend on urllib3. For example The bigtable package and many more.

Upvotes: 2

Devarshi Goswami
Devarshi Goswami

Reputation: 1225

specifying my urllib3 to 1.26.15 in the requirement.txt file based on this https://github.com/urllib3/urllib3/issues/2168#issuecomment-1535838106 thread fixed this error.

Upvotes: 10

Ramon Orraca
Ramon Orraca

Reputation: 111

I'm unsure what caused this error, but I could fix it by importing boto3 into my function's requirements.

Upvotes: 0

Bhavesh Achhada
Bhavesh Achhada

Reputation: 323

I specified the version of urllib3 in requirements.txt file. urllib3==1.26.15 as suggested by @devarshi-goswami in this answer.

Then I got another error ImportError: Cannot find module named WebOb which was resolved by specifying WebOb==1.8.7 in the requirements.txt file.

Conclusion: My requirements.txt file contains

urllib3==1.26.15
WebOb==1.8.7

Upvotes: 0

Raja Amer Khan
Raja Amer Khan

Reputation: 1519

You can resolve it by specifying the lower version of urllib in your requirements.txt file.

requests
urllib3<2

Upvotes: 2

Related Questions