Import error when using netmiko with django : No m

2020-05-09 22:15发布

问题:

Netmiko works fine when I execute below script file (test.py) from the linux cli

#!/var/www/html/devopsenv/bin/python

from netmiko import ConnectHandler import getpass

cisco_asr = { 'device_type': 'cisco_xr', 'ip': 'my ip', 'username': 'user', 'password': 'pass', 'verbose': True }

net_connect = ConnectHandler(**cisco_asr)

config_commands = [ 'int BE222.2481',
                   'vrf devops_test',
                   'ip add 10.1.1.1/30']

output = net_connect.send_config_set(config_commands)
#net_connect.commit()
print(output)

However when I try to use the same script from a django view by importing as below, I get the import error.

from netmiko import ConnectHandler

import error picture

ImportError at /
No module named '_cffi_backend'
Request Method: GET
Request URL:    http://W.X.Y.Z/
Django Version: 2.1.4
Exception Type: ImportError
Exception Value:    
No module named '_cffi_backend'
Exception Location: /var/www/html/devopsenv/lib/python3.6/site-packages/bcrypt/__init__.py in <module>, line 25
Python Executable:  
Python Version: 3.5.6
Python Path:    
['/var/www/html/devops',
 '/var/www/html/devopsenv/lib/python3.6/site-packages',
 '/lib64/python35.zip',
 '/lib64/python3.5',
 '/lib64/python3.5/plat-linux',
 '/lib64/python3.5/lib-dynload',
 '/lib64/python3.5/site-packages',
 '/lib/python3.5/site-packages']

回答1:

found the problem works perfectly with python 3.5 seems there is a bug on python 3.6 that causes it to throw the cffi-backend error when used with netmiko