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

Viewed 43662

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?

9 Answers

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

sudo pip install awscli --ignore-installed six

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.

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.

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

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

Please update the latest urllib package:

run :

pip3 uninstall urllib3
pip3 uninstall urllib3

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.

Related