Upgrade removes pycrypto; Causes import error #1492

Closed
opened 2025-12-29 16:32:27 +01:00 by adam · 8 comments
Owner

Originally created by @MTecknology on GitHub (Jan 13, 2018).

Issue type

[ ] Feature request
[x] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.3
  • NetBox version: 2.2.8

Description

When upgrading netbox, the ./upgrade.sh script removes the installed pycrypto module because it is present in old_requirements.txt. However, this module is needed at line 5 of netbox/secrets/models.py (from Crypto.Cipher import AES, PKCS1_OAEP). This causes ./upgrade.sh to break.

My current solution is to run ./upgrade.sh, let it fail, 'pip install pycrypto', and then run the migrate and collectstatic operations via manage.py.

It looks like the intention was to replace pycrypto with pycryptodome, so I'm assuming my current solution is not ideal.

Error

Successfully installed Django-1.11.9 Markdown-2.6.11 Pillow-5.0.0 asn1crypto-0.24.0 cffi-1.11.4 django-tables2-1.17.1 djangorestframework-3.7.7 graphviz-0.8.2 pynacl-1.2.1 setuptools-38.4.0
Applying database migrations (python3 netbox/manage.py migrate)...
Traceback (most recent call last):
  File "netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute
    django.setup()
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/opt/netbox-venv/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/srv/webapps/netbox/netbox/secrets/models.py", line 5, in <module>
    from Crypto.Cipher import AES, PKCS1_OAEP
ImportError: cannot import name 'AES'
Collecting static files (python3 netbox/manage.py collectstatic --no-input)...
Traceback (most recent call last):
  File "netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute
    django.setup()
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/opt/netbox-venv/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/srv/webapps/netbox/netbox/secrets/models.py", line 5, in <module>
    from Crypto.Cipher import AES, PKCS1_OAEP
ImportError: cannot import name 'AES'
Originally created by @MTecknology on GitHub (Jan 13, 2018). ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [x] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.5.3 * NetBox version: 2.2.8 ### Description When upgrading netbox, the ./upgrade.sh script removes the installed pycrypto module because it is present in old_requirements.txt. However, this module is needed at line 5 of netbox/secrets/models.py (from Crypto.Cipher import AES, PKCS1_OAEP). This causes ./upgrade.sh to break. My current solution is to run ./upgrade.sh, let it fail, 'pip install pycrypto', and then run the migrate and collectstatic operations via manage.py. It looks like the intention was to replace pycrypto with pycryptodome, so I'm assuming my current solution is not ideal. ### Error ``` Successfully installed Django-1.11.9 Markdown-2.6.11 Pillow-5.0.0 asn1crypto-0.24.0 cffi-1.11.4 django-tables2-1.17.1 djangorestframework-3.7.7 graphviz-0.8.2 pynacl-1.2.1 setuptools-38.4.0 Applying database migrations (python3 netbox/manage.py migrate)... Traceback (most recent call last): File "netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute django.setup() File "/opt/netbox-venv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models() File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/opt/netbox-venv/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 673, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 673, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "/srv/webapps/netbox/netbox/secrets/models.py", line 5, in <module> from Crypto.Cipher import AES, PKCS1_OAEP ImportError: cannot import name 'AES' Collecting static files (python3 netbox/manage.py collectstatic --no-input)... Traceback (most recent call last): File "netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/opt/netbox-venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute django.setup() File "/opt/netbox-venv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models() File "/opt/netbox-venv/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/opt/netbox-venv/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 673, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 673, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "/srv/webapps/netbox/netbox/secrets/models.py", line 5, in <module> from Crypto.Cipher import AES, PKCS1_OAEP ImportError: cannot import name 'AES' ```
adam closed this issue 2025-12-29 16:32:27 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 15, 2018):

pycryptodome is listed in requirements.txt, and pip install -r requirements.txt is called before any of the manage.py functions. You'll need to find out why pycryptodome isn't getting installed. What happens when you try to install it manually (pip[3] install pycryptodome)?

@jeremystretch commented on GitHub (Jan 15, 2018): pycryptodome is listed in requirements.txt, and `pip install -r requirements.txt` is called before any of the manage.py functions. You'll need to find out why pycryptodome isn't getting installed. What happens when you try to install it manually (`pip[3] install pycryptodome`)?
Author
Owner

@MTecknology commented on GitHub (Jan 20, 2018):

I do have pycryptodome installed. After activating the virtualenv, pip freeze shows pycryptodome==3.4.7.

@MTecknology commented on GitHub (Jan 20, 2018): I do have pycryptodome installed. After activating the virtualenv, pip freeze shows pycryptodome==3.4.7.
Author
Owner

@jeremystretch commented on GitHub (Jan 22, 2018):

  File "/srv/webapps/netbox/netbox/secrets/models.py", line 5, in <module>
    from Crypto.Cipher import AES, PKCS1_OAEP
ImportError: cannot import name 'AES'

This error indicates that the environment in which NetBox is running does not have the pycryptodome package installed. This is something you'll need to correct in your specific deployment, and not something we can address in NetBox.

@jeremystretch commented on GitHub (Jan 22, 2018): ``` File "/srv/webapps/netbox/netbox/secrets/models.py", line 5, in <module> from Crypto.Cipher import AES, PKCS1_OAEP ImportError: cannot import name 'AES' ``` This error indicates that the environment in which NetBox is running does not have the pycryptodome package installed. This is something you'll need to correct in your specific deployment, and not something we can address in NetBox.
Author
Owner

@MTecknology commented on GitHub (Jan 22, 2018):

As I already mentioned... it /is/ installed.

$ pip3 freeze
asn1crypto==0.24.0
bcrypt==3.1.4
certifi==2017.11.5
cffi==1.11.4
chardet==3.0.4
coreapi==2.3.3
[...]
py-gfm==0.1.3
pyasn1==0.4.2
pycparser==2.18
pycrypto==2.6.1
pycryptodome==3.4.7
PyNaCl==1.2.1
pytz==2017.3
[...]

Why was this closed?

@MTecknology commented on GitHub (Jan 22, 2018): As I already mentioned... it /is/ installed. ``` $ pip3 freeze asn1crypto==0.24.0 bcrypt==3.1.4 certifi==2017.11.5 cffi==1.11.4 chardet==3.0.4 coreapi==2.3.3 [...] py-gfm==0.1.3 pyasn1==0.4.2 pycparser==2.18 pycrypto==2.6.1 pycryptodome==3.4.7 PyNaCl==1.2.1 pytz==2017.3 [...] ``` Why was this closed?
Author
Owner

@jeremystretch commented on GitHub (Jan 22, 2018):

Yes, pip shows that the package is installed on the system. That does not mean the environment in which you're running NetBox has access to it, hence the error.

@jeremystretch commented on GitHub (Jan 22, 2018): Yes, pip shows that the package is installed on the system. That does not mean the environment in which you're running NetBox has access to it, hence the error.
Author
Owner

@MTecknology commented on GitHub (Jan 22, 2018):

Is there a particular way pycryptodome needs to be built?

Other functions import fine..

>>> from Crypto.Cipher import PKCS1_OAEP
>>> 
@MTecknology commented on GitHub (Jan 22, 2018): Is there a particular way pycryptodome needs to be built? Other functions import fine.. ``` >>> from Crypto.Cipher import PKCS1_OAEP >>> ```
Author
Owner

@jeremystretch commented on GitHub (Jan 22, 2018):

pycrypto==2.6.1
pycryptodome==3.4.7

Remove pycrypto. The pycryptodome package replaces it.

@jeremystretch commented on GitHub (Jan 22, 2018): ``` pycrypto==2.6.1 pycryptodome==3.4.7 ``` Remove pycrypto. The pycryptodome package replaces it.
Author
Owner

@davcamer commented on GitHub (Feb 22, 2018):

Notes for future searchers: I ended up in a similar situation by running pip3 install -r requirements.txt before running ./upgrade.sh. I was following the install procedure before remembering there was an upgrade script.

This installed pycryptodome, and then uninstall pycrypto. Because pycryptodome is a drop-in replacement, there are name clashes, and pycryptodome ends up damaged after uninstalling pycrypto.

A quick fix is uninstalling and reinstall pycryptodome:

pip3 uninstall pycryptodome
pip3 install pycryptodome
@davcamer commented on GitHub (Feb 22, 2018): Notes for future searchers: I ended up in a similar situation by running `pip3 install -r requirements.txt` before running `./upgrade.sh`. I was following the install procedure before remembering there was an upgrade script. This installed pycryptodome, and then uninstall pycrypto. Because pycryptodome is a drop-in replacement, there are name clashes, and pycryptodome ends up damaged after uninstalling pycrypto. A quick fix is uninstalling and reinstall pycryptodome: ``` pip3 uninstall pycryptodome pip3 install pycryptodome ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1492