from urllib3.util.ssl_ import ( ImportError: cannot import name ssl

Question:

My resources:

Python 2.7, Ubunutu 18.04, Pycharm, virtual box oracle

I have an automation solution built in python.
The solution can be run from both cmd or pycharm of course.
2 options to run automation solution.

python main.py args a,b,c...(run 1 suite of tests)
python jenkinsRun.py arg a,b,c...(run main.py with diff args each time -lets say 5 time for instance)

Once jenkinsRun.py is runnig it will execute each main.py like this:

os.system('python main.py %s %s %s %s %s %s'%(STD,config.VpcStackName, '-dryrun', 'false', '-tenant' ,config.PROD_STAGE_Tenant))

Note that this is how I implemented it 3 years ago..could be better ways like using __import__, but need way to pass arguments, etc…

Anyway, when run:

python main.py arg a,b,c..

All good.

When run:

jenkinsRun.py

which should run main each time with diff args I get exception:

"/home/ohad/.local/lib/python2.7/site-packages/botocore/httpsession.py", line 7, in <module>
    from urllib3.util.ssl_ import (
ImportError: cannot import name ssl

This happend only when I run the code on my new environment (see resources above)
last week I had old virtul box with ubuntu 15.04 (old) which everything worked well (didn’t touch the vode ever since).

I have installed on new virtual box from scratch libaries, drivers, etc, etc.

Any ideas?

Asked By: ohadshay

||

Answers:

Just to make sure: are you certain that you are invoking Python 2.x ?

Ubuntu 18.04 has Python 3.x as default, so make sure that you are not accidentally starting the script using another python version.

Answered By: Ralf

I had a similar error after creating a new environment (which also uses Boto3). It turned out to be a DLL error (ImportError: DLL load failed), which was caught by SSL module resulting in the error from the question: ImportError: cannot import name ssl.

Solution for me was to add an additional folder to the path: path_to_anaconda/Anaconda3/Library/bin. In that way, DLL load succeeds and the given ImportError is resolved.

Answered By: Guido

Could be some issue with installation. I did re-installed on MAC and it worked

sudo pip install awscli --ignore-installed six

I was working in PyCharm when I hit this wall.

Solved it by redirecting the path to my Anaconda environment, which I keep better provisioned and up to date.

Select Edit Configurations

enter image description here

Answered By: leerssej

Update the latest version of awscli resolved on my Mac by the below command line.

curl "https://awscli.amazonaws.com/AWSCLIV2-2.0.30.pkg" -o

"AWSCLIV2.pkg" sudo installer -pkg AWSCLIV2.pkg -target /

Reference:

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html#cliv2-mac-install-cmd

Answered By: Long Nguyen

After uninstalling, installing, even creating environments… this worked for me!

https://stackoverflow.com/a/60405693

Answered By: PhilGa

I am not sure why it worked. But, I had this issue in AWS Glue, and I was able to get around this problem by using Glue 3.0 instead of Glue 2.0.

Answered By: Jeong Kim

In my case this issue came apparently from having colliding versions of boto3, botocore and awscli. This fixed the issue in my case:

pip install boto3 botocore awscli aiobotocore --ignore-installed
Answered By: ronkov

Please update the latest urllib package:

run :

pip3 uninstall urllib3
pip3 install urllib3
Answered By: Mukul Kirti Verma

I was getting the same error on Win 10 and VS Code was pointing at the Conda interpreter. The issue was solved by installing Python 3.11 outside of Conda and pointing at the new interpreter. Don’t forget to add the new Python to PATH and install boto3 afterwards.

Answered By: Roman

If you are using boto3 as a dependency, there was a bug with how the boto3 dependencies were managed.

try running
pip3 install boto3 --upgrade to update boto3 and the issue should be resolved!

Answered By: Isaac N.
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.