本質的に構成ファイルを取り込み、行にカットしてリストに追加したSSH経由でルーターにプッシュしようとします。以下のコードスニペット。Netmikoエラー:UnicodeDecodeError: 'ascii'コーデックは、位置0のバイト0xffをデコードできません:序数が範囲内にありません(128)
['!\n', 'version 15.6\n', '!\n', 'enable\r\n', 'configure terminal\r\n', 'no service timestamps debug uptime\r\n', 'no service timestamps log uptime\r\n', '!\r\n', 'hostname IOSV4\r\n', '!\r\n', 'no ip domain lookup\r\n', 'ip routing\r\n', 'ipv6 unicast-routing\r\n', '!\r\n', 'cdp run\r\n',line con 0\r\n', ' exec-timeout 0 0\r\n', ' logging synchronous\r\n', ' privilege level 15\r\n', ' no login\r\n', '!\r\n', 'line vty 0 4\r\n', ' privilege level 15\r\n', ' no login\r\n', '!\r\n', 'end\r\n', '\r\n', '\n', '!\n', 'end\n']
は、私が過去にこれを実行していると、この問題が発生した覚えていないので、私は」:
device_ip = "192.168.1.5"
selected_cmd_file = open('{}.txt'.format("Router1"), 'rb')
print("[+] Pushing scenario configuration for device {}.".format("Router1))
command_set = []
selected_cmd_file.seek(0)
for each_line in selected_cmd_file.readlines():
command_set.append(each_line)
net_connect = ConnectHandler(device_type = device, ip = device_ip, username = radiususer, password = radiuspass)
output = net_connect.send_config_set(command_set)
net_connect.disconnect()
リストに追加した後、ファイルの内容のための出力は、次のようになります私は何が欠けているかわからない。これも助けになるかもしれません(Linuxから見たファイルタイプ)
file IOSV4.txt
IOSV4.txt: ASCII text, with CRLF, LF line terminators
は 'rb'?なぜこの方法を使うのですか? – dsgdfg
「r」と「rb」で試してみてください。同じ結果。 – OfWolfAndMan
include_textとfile_encodingは一致しません。linuxでこのファイルを作成し、エンコードシステムには触れないでください(Windowsではファイルを作成し、Linuxではこれを使用しないでください、関連する 'txt'ファイルの最初の4バイトについて)。 – dsgdfg