Ubuntu AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK' when running aws cli

When I run aws command which is installed via apt command, I get

Traceback (most recent call last):
  File "/usr/bin/aws", line 19, in 
    import awscli.clidriver
  File "/usr/lib/python3/dist-packages/awscli/clidriver.py", line 17, in 
    import botocore.session
  File "/usr/lib/python3/dist-packages/botocore/session.py", line 28, in 
    import botocore.configloader
  File "/usr/lib/python3/dist-packages/botocore/configloader.py", line 19, in 
    from botocore.compat import six
  File "/usr/lib/python3/dist-packages/botocore/compat.py", line 25, in 
    from botocore.exceptions import MD5UnavailableError
  File "/usr/lib/python3/dist-packages/botocore/exceptions.py", line 15, in 
    import requests
  File "/usr/lib/python3/dist-packages/requests/__init__.py", line 95, in 
    from urllib3.contrib import pyopenssl
  File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in 
    import OpenSSL.SSL
  File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in 
    from OpenSSL import crypto, SSL
  File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in 
    class X509StoreFlags(object):
  File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in 
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in 
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in 
    import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket
  File "/usr/lib/python3/dist-packages/requests_unixsocket/__init__.py", line 1, in 
    import requests
  File "/usr/lib/python3/dist-packages/requests/__init__.py", line 95, in 
    from urllib3.contrib import pyopenssl
  File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in 
    import OpenSSL.SSL
  File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in 
    from OpenSSL import crypto, SSL
  File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in 
    class X509StoreFlags(object):
  File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

Original exception was:
Traceback (most recent call last):
  File "/usr/bin/aws", line 19, in 
    import awscli.clidriver
  File "/usr/lib/python3/dist-packages/awscli/clidriver.py", line 17, in 
    import botocore.session
  File "/usr/lib/python3/dist-packages/botocore/session.py", line 28, in 
    import botocore.configloader
  File "/usr/lib/python3/dist-packages/botocore/configloader.py", line 19, in 
    from botocore.compat import six
  File "/usr/lib/python3/dist-packages/botocore/compat.py", line 25, in 
    from botocore.exceptions import MD5UnavailableError
  File "/usr/lib/python3/dist-packages/botocore/exceptions.py", line 15, in 
    import requests
  File "/usr/lib/python3/dist-packages/requests/__init__.py", line 95, in 
    from urllib3.contrib import pyopenssl
  File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in 
    import OpenSSL.SSL
  File "/usr/lib/python3/dist-packages/OpenSSL/__init__.py", line 8, in 
    from OpenSSL import crypto, SSL
  File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in 
    class X509StoreFlags(object):
  File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
    CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

How to fix this? I tried apt update && apt upgrade but nothing worked so far.

It seems that python3-aioopenssl and python3-openssl are not updated on Ubuntu Linux. I tired to update it via apt update&& apt upgrade but it didn’t worked. Next solution was to use the

pip3 install pyOpenSSL --upgrade

I avoided this one. Instead I removed awscli package on ubuntu 20.04:

sudo apt --purge remove awscli

I installed snap package named aws-cli which I think is the official package from AWS itself:

snap info aws-cli
sudo snap install aws-cli --classic

Now aws cli working:

aws --version
aws-cli/1.15.58 Python/3.5.2 Linux/5.15.0-67-generic botocore/1.10.57

I went with snap package because it is isolated environment with all dependencies and left Python 3 and pip as it is on my Ubuntu machine.