AWS Lambda因URLLIB导致导入错误。

huangapple go评论69阅读模式
英文:

AWS lambda throwing import error because of URLLIB

问题

I'm running a python script on AWS Lambda and it's 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.
I'm only using urllib to parse and unquote URLs, namely:

from urllib.parse import urlparse

and

from urllib.parse import unquote

Like it's mentioned in the GitHub URL, I can upgrade my Python version, but doing so would break other things.
Are there any alternative libraries I can use to get the same result?

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

英文:

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

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

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.

答案1

得分: 7

将我的requirement.txt文件中的urllib3版本指定为1.26.15,参考这个链接 https://github.com/urllib3/urllib3/issues/2168#issuecomment-1535838106 中的讨论解决了这个错误。

英文:

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.

答案2

得分: 2

升级您的AWS Lambda函数运行时至Python 3.10,它应该能够正常工作。

英文:

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

答案3

得分: 1

你可以通过在 requirements.txt 文件中指定 urllib 的较低版本来解决此问题。

requests
urllib3&lt;2
英文:

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

requests
urllib3&lt;2

答案4

得分: 1

如果您查看错误消息中的GH问题,您会发现该问题仅出现在Python >=3.7但<3.10的版本中。

升级到Python 3.10,问题解决。

英文:

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

答案5

得分: 1

我因我的Pipenv文件中以下pip要求而遇到了这个问题:

requests = ">= 2.28.2, < 3"

出了什么问题:

  • requests 依赖于 urllib3
  • 在 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"

实际上,将 requests 2.29 升级到 2.30 的次要版本升级导致了 urllib3 版本从 1.x 升级到 2.x。这是不兼容的,需要系统上安装更新的 OpenSSL 库。

我的简单解决方案是将我的 requests 依赖项更改为

requests = ">= 2.28.2, < 2.29.0"

其他依赖于 urllib3 的 pip 依赖项可能会出现类似的错误,例如 bigtable 包等。

英文:

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

requests = &quot;&gt;= 2.28.2, &lt; 3&quot;

What went wrong:

  • requests depends on urllib3
  • this dependency changed in requests 2.30.
    • requests/setup.py v2.29.0: &quot;urllib3&gt;=1.21.1,&lt;1.27&quot;
    • requests/setup.py v2.30.0: &quot;urllib3&gt;=1.21.1,&lt;3&quot;

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 = &quot;&gt;= 2.28.2, &lt; 2.29.0&quot;

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

答案6

得分: 0

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

我花了相当多的时间来做这个,最终做了一些事情。

I'm using python 3.8.16

我正在使用Python 3.8.16

  1. I installed the openssl11

  2. 我安装了openssl11

sudo yum install openssl11

sudo yum install openssl11

  1. found the existing runtime.

  2. 找到了现有的运行时。

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

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

  1. renamed the old openssl

  2. 重命名旧的openssl

sudo mv openssl openssl102

sudo mv openssl openssl102

  1. symlinked the new version

  2. 创建了新版本的符号链接

ln -s openssl11 openssl

ln -s openssl11 openssl

  1. in the appropriate build directory, i then rebuilt the target python modules under the supported version.

  2. 在适当的构建目录中,我重新构建了受支持版本下的目标Python模块。

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

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

英文:

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
    

答案7

得分: 0

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
英文:

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

答案8

得分: 0

我不确定是什么导致了这个错误,但我可以通过将boto3导入到我的函数的要求中来修复它。

英文:

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

答案9

得分: 0

我使用较旧版本的urllib库解决了这个问题,当我安装我代码所需的所有其他库时:

python -m pip install urllib3==1.26.16 --no-deps -t
英文:

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 

答案10

得分: 0

我遇到了这个问题,对我有效的解决方法是在本地安装了 urllib 版本 1.26.16,并将其制作成 zip 文件,然后将这个 zip 文件添加到层中。我将其与 openai 一起使用,因为我们正在层中添加依赖项。

pip install openai urllib3==1.26.16
英文:

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

huangapple
  • 本文由 发表于 2023年5月6日 23:53:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定