无法将 2 个变量传递给预期;字符串索引必须是整数,而不是 str
Having trouble passing 2 variables to pexpect; string indices must be integers, not str
正在尝试从无线控制器中提取数据。
命令是 show ap auto-rf
频段可以是 802.11a 802.11b 或 802.11-abgn
ap-name 是任意的
示例输出:
(思科控制器)>show ap auto-rf 802.11-abgn Hallway38
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)
正在尝试从无线控制器中提取数据。 命令是 show ap auto-rf 频段可以是 802.11a 802.11b 或 802.11-abgn ap-name 是任意的
示例输出:
(思科控制器)>show ap auto-rf 802.11-abgn Hallway38
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)