ansible

Fix Error – ImportError: No module named packages.urllib3.exceptions

Recently when I was creating Python automation script I faced this weird error. This literally wasted my couple of days and needless to mentioned frustration it caused.

Below is the error message which I was getting

*
fatal: [127.0.0.1]: FAILED! => {"changed": true
 "cmd": "python CreateFileSystem.py i-06a848f20bafd0475 10G"
 "delta": "0:00:00.077332"
 "end": "2019-11-21 06:58:53.018383"
 "msg": "non-zero return code"
 "rc": 1
 "start": "2019-11-21 06:58:52.941051"
 "stderr": "CreateFileSystem.py:49: SyntaxWarning: name 'unity_headers' is used prior to global declaration\n  global unity_headers\nTraceback (most recent call last):\n  File \"CreateFileSystem.py\"
 line 5
 in <module>\n    from requests.packages.urllib3.exceptions import InsecureRequestWarning\nImportError: No module named packages.urllib3.exceptions"
 "stderr_lines": ["CreateFileSystem.py:49: SyntaxWarning: name 'unity_headers' is used prior to global declaration"
 "  global unity_headers"
 "Traceback (most recent call last):"
 "  File \"CreateFileSystem.py\"
 line 5
 in <module>"
 "    from requests.packages.urllib3.exceptions import InsecureRequestWarning"
 "ImportError: No module named packages.urllib3.exceptions"]
 "stdout": ""
 "stdout_lines": []}

As you can see from the error it keeps saying that there’s error importing “urllib3” package. But This was already installed in the system

For resolving this I had to follow below steps.

  • Uninstall below packages
    • python-devel
    • libevent-devel
    • openssl-devel
    • libffi-devel
    • Requests (pip)
    • urllib3 (pip)
  • Install below packages
    • python-devel
    • libevent-devel
    • openssl-devel
    • libffi-devel
  • Run below command
pip install requests urllib3

These steps should resolved the issue I was facing.

Also note that DO NOT install pip packges (requests and urllib3) individually, run them as single command. This makes sure that required pip dependencies are also auto installed. Strangely I haven’t seen dependencies getting installed when you install them one by one.

Categories: ansible

Tagged as: , , , ,

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s