Synss / python-mbedtls

Cryptographic library with an mbed TLS back end
MIT License
79 stars 28 forks source link

ModuleNotFoundError: No module named 'mbedtls.exceptions' #36

Closed AchmadFathoni closed 3 years ago

AchmadFathoni commented 3 years ago

NOTE: Please use stackoverflow for support questions. This repository's issues are reserved for feature requests and bug reports.

I am submitting a …

Description

Missing mbedtls.exceptions module when importing mbedtls.cipher

Current behavior

Error when importing mbedtls.cipher

Expected behavior

python can find mbedtls.exception module

Steps to reproduce

  1. Install python-mbedtls version 1.4.0
  2. Import mbedtls.cipher module

Minimal demo of the problem

>>> from mbedtls import cipher
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/mbedtls/__init__.py", line 8, in <module>
    import mbedtls.cipher as cipher
  File "/usr/lib/python3.8/site-packages/mbedtls/cipher/__init__.py", line 12, in <module>
    from . import AES, ARC4, ARIA, CHACHA20, DES, DES3, Blowfish, Camellia, DES3dbl
  File "/usr/lib/python3.8/site-packages/mbedtls/cipher/AES.py", line 11, in <module>
    from mbedtls.exceptions import TLSError
ModuleNotFoundError: No module named 'mbedtls.exceptions'

## Other information

Synss commented 3 years ago

Hi @AchmadFathoni!

Thank you for your message. Which OS are you using? Do you have the build log?

AchmadFathoni commented 3 years ago

I am using Arch Linux. This is the result of python setup.py install --user

running install
running bdist_egg
running egg_info
writing src/python_mbedtls.egg-info/PKG-INFO
writing dependency_links to src/python_mbedtls.egg-info/dependency_links.txt
writing requirements to src/python_mbedtls.egg-info/requires.txt
writing top-level names to src/python_mbedtls.egg-info/top_level.txt
reading manifest file 'src/python_mbedtls.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'src/python_mbedtls.egg-info/SOURCES.txt'
installing library code to build/3.8.6/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/exceptions.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/hkdf.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/mpi.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/pk.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/tls.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/version.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/x509.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/_md.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/_platform.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/_random.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/_ringbuf.c' Cython extension (up-to-date)
skipping 'build/3.8.6/temp.linux-x86_64-3.8/pyrex/mbedtls/cipher/_cipher.c' Cython extension (up-to-date)
creating build/3.8.6/bdist.linux-x86_64
creating build/3.8.6/bdist.linux-x86_64/egg
creating build/3.8.6/bdist.linux-x86_64/egg/mbedtls
creating build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/AES.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/ARC4.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/ARIA.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/Blowfish.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/Camellia.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/CHACHA20.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/DES.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/DES3.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/DES3dbl.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/_cipher.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/cipher/__init__.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/exceptions.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/hashlib.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/hkdf.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/hmac.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/mpi.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/pk.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/secrets.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/tls.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/version.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/x509.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/_md.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/_platform.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/_random.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/_ringbuf.cpython-38-x86_64-linux-gnu.so -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
copying build/3.8.6/lib.linux-x86_64-3.8/mbedtls/__init__.py -> build/3.8.6/bdist.linux-x86_64/egg/mbedtls
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/AES.py to AES.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/ARC4.py to ARC4.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/ARIA.py to ARIA.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/Blowfish.py to Blowfish.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/Camellia.py to Camellia.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/CHACHA20.py to CHACHA20.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/DES.py to DES.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/DES3.py to DES3.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/DES3dbl.py to DES3dbl.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/__init__.py to __init__.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/hashlib.py to hashlib.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/hmac.py to hmac.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/secrets.py to secrets.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/__init__.py to __init__.cpython-38.pyc
creating stub loader for mbedtls/exceptions.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/hkdf.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/mpi.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/pk.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/tls.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/version.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/x509.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/_md.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/_platform.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/_random.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/_ringbuf.cpython-38-x86_64-linux-gnu.so
creating stub loader for mbedtls/cipher/_cipher.cpython-38-x86_64-linux-gnu.so
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/exceptions.py to exceptions.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/hkdf.py to hkdf.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/mpi.py to mpi.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/pk.py to pk.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/tls.py to tls.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/version.py to version.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/x509.py to x509.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/_md.py to _md.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/_platform.py to _platform.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/_random.py to _random.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/_ringbuf.py to _ringbuf.cpython-38.pyc
byte-compiling build/3.8.6/bdist.linux-x86_64/egg/mbedtls/cipher/_cipher.py to _cipher.cpython-38.pyc
creating build/3.8.6/bdist.linux-x86_64/egg/EGG-INFO
copying src/python_mbedtls.egg-info/PKG-INFO -> build/3.8.6/bdist.linux-x86_64/egg/EGG-INFO
copying src/python_mbedtls.egg-info/SOURCES.txt -> build/3.8.6/bdist.linux-x86_64/egg/EGG-INFO
copying src/python_mbedtls.egg-info/dependency_links.txt -> build/3.8.6/bdist.linux-x86_64/egg/EGG-INFO
copying src/python_mbedtls.egg-info/requires.txt -> build/3.8.6/bdist.linux-x86_64/egg/EGG-INFO
copying src/python_mbedtls.egg-info/top_level.txt -> build/3.8.6/bdist.linux-x86_64/egg/EGG-INFO
writing build/3.8.6/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
mbedtls.__pycache__._md.cpython-38: module references __file__
mbedtls.__pycache__._platform.cpython-38: module references __file__
mbedtls.__pycache__._random.cpython-38: module references __file__
mbedtls.__pycache__._ringbuf.cpython-38: module references __file__
mbedtls.__pycache__.exceptions.cpython-38: module references __file__
mbedtls.__pycache__.hkdf.cpython-38: module references __file__
mbedtls.__pycache__.mpi.cpython-38: module references __file__
mbedtls.__pycache__.pk.cpython-38: module references __file__
mbedtls.__pycache__.tls.cpython-38: module references __file__
mbedtls.__pycache__.version.cpython-38: module references __file__
mbedtls.__pycache__.x509.cpython-38: module references __file__
mbedtls.cipher.__pycache__._cipher.cpython-38: module references __file__
creating dist
creating 'dist/python_mbedtls-1.4.0-py3.8-linux-x86_64.egg' and adding 'build/3.8.6/bdist.linux-x86_64/egg' to it
removing 'build/3.8.6/bdist.linux-x86_64/egg' (and everything under it)
Processing python_mbedtls-1.4.0-py3.8-linux-x86_64.egg
creating /home/toni/.local/lib/python3.8/site-packages/python_mbedtls-1.4.0-py3.8-linux-x86_64.egg
Extracting python_mbedtls-1.4.0-py3.8-linux-x86_64.egg to /home/toni/.local/lib/python3.8/site-packages
Adding python-mbedtls 1.4.0 to easy-install.pth file

Installed /home/toni/.local/lib/python3.8/site-packages/python_mbedtls-1.4.0-py3.8-linux-x86_64.egg
Processing dependencies for python-mbedtls==1.4.0
Searching for certifi==2020.6.20
Best match: certifi 2020.6.20
Adding certifi 2020.6.20 to easy-install.pth file

Using /usr/lib/python3.8/site-packages
Finished processing dependencies for python-mbedtls==1.4.0
AchmadFathoni commented 3 years ago

Wait a minute, the error is gone when installing from source or from pip directly. Previously I was installing from pipenv.

AchmadFathoni commented 3 years ago

Just for the record: compiling with --optimize=1 flag produces same error.

Synss commented 3 years ago

Thank you! I will have a look.

AchmadFathoni commented 3 years ago

Just for the record: compiling with --optimize=1 flag produces same error.

Actually, that flag is not the cause. I get above error from compiling source that I downloaded from https://files.pythonhosted.org/packages/89/2b/205012368e9e8c58c25153664711596a0f206432d900477729a391879408/python-mbedtls-1.4.0.tar.gz . Compiling the source from https://github.com/Synss/python-mbedtls/archive/1.4.0.tar.gz is fine. Both tar.gz have different hash.

Synss commented 3 years ago

You are right, some files are missing from the archive on pypi. That could also explain Issue #35 as well. I will have to check that.

Synss commented 3 years ago

1.4.1 should have fixed that. Could you please try once more and report here? Thank you.

AchmadFathoni commented 3 years ago

Yes, I can do >>> from mbedtls import cipher now. Btw, I have made AUR package for python-mbedtls. It would be nice if you can add that AUR package link to Installation section in README.md