IndentationError:期望在嵌套for循环中出现缩进块



我不确定我的缩进错误是与我的代码。我得到这个错误:

File "ex1.py", line 43
if v == 'arista_eos':
^
IndentationError: expected an indented block

下面是给我错误的代码:

for line in devices:
for k, v in line.items():
if v == 'juniper_junos':
try:
net_conn = ConnectHandler(**line)
config = net_conn.send_command("show config | display set")
filename = net_conn.host + '_' + time
with open(filename, mode='w') as f:
cwd = os.getcwd()
cfl = cwd + '/' + filename
f.write(config)
shutil.move(cfl, direct)
except NoValidConnectionsError:
if v == 'arista_eos':
try:
net_conn = ConnectHandler(**line)
config = net_conn.send_command("show run")
filename = net_conn.host + '_' + time
with open(filename, mode='w') as f:
cwd = os.getcwd()
cfl = cwd + '/' + filename
f.write(config)
shutil.move(cfl, direct)
except (NetMikoTimeoutException, NoValidConnectionsError, NameError):
except NoValidConnectionsError:
if v == 'arista_eos':

except NoValidConnectionsError:之后必须有一个缩进块,指定NoValidConnectionsError的情况下应该发生什么:

except NoValidConnectionsError:
# indented block here
if v == 'arista_eos':

由于某种原因你省略了这个,这是无效的。

最新更新