在 Golang 中调用 targetcli 命令进行交互操作时发现报了如下的错误:
Go
Copy
exit status 1
exit status 1: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/configshell_fb/shell.py", line 893, in run_interactive
old_completer = readline.get_completer()
NameError: name 'readline' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/targetcli", line 121, in <module>
main()
File "/usr/bin/targetcli", line 111, in main
shell.run_interactive()
File "/usr/lib/python3/dist-packages/configshell_fb/shell.py", line 899, in run_interactive
readline.set_completer(old_completer)
NameError: name 'readline' is not defined
网上查了下资料应该是 python config shell 的 bug 导致在交互命令下 readline 不能正常的工作
具体的 pr Commit82f79eb
下面升级下 config shel
$pip3 list 查看 python 的依赖的 package
configshell-fb (1.1.20)
果然 1.1.20 是有问题的
下面对 configshell 进行升级
Go
Copy
$pip3 install --upgrade configshell-fb
Collecting configshell-fb
Downloading http://mirrors.aliyun.com/pypi/packages/24/c6/4b2400d1872bda4309f552cb293d1937eda3e7bf3c0cf38e43eb7b4a41d9/configshell-fb-1.1.29.tar.gz (55kB)
100% |████████████████████████████████| 61kB 1.8MB/s
Requirement already up-to-date: pyparsing<3.0,>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from configshell-fb)
Requirement already up-to-date: six in /usr/local/lib/python3.6/dist-packages (from configshell-fb)
Collecting urwid (from configshell-fb)
Downloading http://mirrors.aliyun.com/pypi/packages/94/3f/e3010f4a11c08a5690540f7ebd0b0d251cc8a456895b7e49be201f73540c/urwid-2.1.2.tar.gz (634kB)
100% |████████████████████████████████| 634kB 1.4MB/s
Building wheels for collected packages: configshell-fb, urwid
Running setup.py bdist_wheel for configshell-fb ... done
Stored in directory: /root/.cache/pip/wheels/33/ec/b5/89c0fa5734c841ccb450964644d99e1abaf9ca7accfe12c354
Running setup.py bdist_wheel for urwid ... done
Stored in directory: /root/.cache/pip/wheels/19/a7/8b/e6971235a6a3628272bb3d58b095a9ac1b935c54c1e28f125f
Successfully built configshell-fb urwid
Installing collected packages: urwid, configshell-fb
Found existing installation: urwid 2.0.1
Not uninstalling urwid at /usr/lib/python3/dist-packages, outside environment /usr
Found existing installation: configshell-fb 1.1.20
Not uninstalling configshell-fb at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed configshell-fb-1.1.29 urwid-2.1.2
参考: