本文介绍了将netmiko与django一起使用时发生导入错误:没有名为"_cffi_backend"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从linux cli执行以下脚本文件(test.py)时,Netmiko可以正常工作

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

从netmiko导入ConnectHandler导入getpass

from netmiko import ConnectHandler import getpass

cisco_asr = { 'device_type':'cisco_xr', 'ip':'我的ip', '用户名':'用户', 'password':'pass', 'verbose':True}

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)

但是,当我尝试通过如下所示的方式从django视图中使用相同的脚本时,出现导入错误.

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

导入错误图片

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']

推荐答案

发现了问题与python 3.5完美搭配似乎在python 3.6上存在一个错误,导致与netmiko一起使用时会引发cffi-backend错误

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

这篇关于将netmiko与django一起使用时发生导入错误:没有名为"_cffi_backend"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 07:09