在将 2 个变量传递给 pexpect 时遇到问题;字符串索引必须是整数,而不是 str



尝试从无线控制器中提取数据。 命令是显示 AP 自动射频 频段可以是 802.11a 802.11b 或 802.11-ABGN AP 名称是任意的

示例输出:

(思科控制器(>显示 AP 自动射频 802.11-abgn 走廊38

Number Of Slots.................................. 2 
AP Name.......................................... Hallway38
MAC Address...................................... a0:e0:af:33:d0:bc
Slot ID........................................ 0
Radio Type..................................... RADIO_TYPE_80211abgn
Current TX/RX Band............................. 80211 2.4G band
Sub-band Type.................................. All
Noise Information
Noise Profile................................ PASSED
Channel 1....................................  -90 dBm
Channel 2....................................  -77 dBm
Channel 3....................................  -88 dBm
Channel 4....................................  -93 dBm
Channel 5....................................  -91 dBm
Channel 6....................................  -88 dBm
Channel 7....................................  -93 dBm

错误输出: 文件 "./wlc-auto-rf.py",第 34 行,在 child.sendline ('show ap auto-rf' ['radio']['apname']( 类型错误:字符串索引必须是整数,而不是 str

任何帮助,不胜感激。

here is the script:
!/usr/bin/python 
#
#       requires python pexpect module
#
import pexpect
import sys
firstarg=sys.argv[0]
address=sys.argv[1]
username=sys.argv[2]
password=sys.argv[3]
radio=sys.argv[4]
apname=sys.argv[5]
output=sys.argv[6]
child = pexpect.spawn ('ssh' , [address])
child.expect ('User:')
child.sendline (username)
child.expect ('Password:')
child.sendline (password)
child.expect ("Controller")
child.sendline ('config paging disable')
#
child.expect ("Controller")
child.sendline ('show ap auto-rf' ['radio']['apname'])
child.logfile = open(output , "w")
child.expect ("Controller")
child.sendline ('logout')
child.expect('(y/N)')
child.sendline ('N')
child.expect(pexpect.EOF)

我能够使用字符串连接将变量一起添加到一个字符串中来修复它 child.sendline ('show ap auto-rf '+radio+' '+apname(

最新更新