在下面的代码中,我在错误处理语句中得到syatax error' 我正在使用ATOM文本编辑器。django用于web界面,netmiko libaray用于我的后端代码。你知道吗
from django.shortcuts import render
from first_app.forms import CmdForm
from django.http import HttpResponse
from netmiko import ConnectHandler
from netmiko.ssh_exception import NetMikoTimeoutException
from paramiko.ssh_exception import SSHException
from netmiko.ssh_exception import AuthenticationException
import datetime, time, sys
# Create your views here.
def index(request):
my_dict = {'insert_me': ""}
return render(request,'first_app/index.html',context=my_dict)
def form_name_view(request):
if request.method == "POST":
form = CmdForm(request.POST)
if form.is_valid():
from netmiko import ConnectHandler
ipInsert = request.POST.get('ip_address', '')
devices = {
'device_type':'cisco_ios',
'ip':ipInsert,
'username':'mee',
'password':'12345',
'secret':'12345',
}
cmd = request.POST.get('command', '')
try:
netconnect = ConnectHandler(**devices)
except(AuthenticationException):
print ('Authentication failed' + ipInsert)
continue #position 1
continue #posiiton 2
getIP = netconnect.send_command(ipInsert)
output = netconnect.send_command(cmd)
now = time.strftime("%Y_%m_%d__%H_%M%S")
file = sys.stdout
file = open("C:/Users/karti/OneDrive/Desktop/frontend/ "+now +".txt", mode='w+')
file.write("IP address is\n"+ ipInsert)
file.write("\n\nCommand Executed: \n"+ cmd)
file.write("\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
file.write("\n\nOutput of Executed Command: \n\n\n"+output)
file.close
return render(request,'first_app/forms.html', {'form': form, 'output':output, 'getIP':getIP, 'date_time':now})
else:
form = CmdForm()
return render(request,'first_app/forms.html', {'form': form})
else:
return render(request,'first_app/forms.html', {})
在位置1继续时出错
from first_app import views File "K:\Work\DevNet\first_project\first_app\views.py", line 33 continue ^ SyntaxError: 'continue' not properly in loop
在位置2继续时出错
File "K:\Work\DevNet\first_project\first_app\views.py", line 33 continue ^ SyntaxError: 'continue' not properly in loop
try
和Exception
似乎没有对齐。你知道吗except
块,在那里您可以捕获从try
块抛出的异常。你知道吗以下代码为真:
相关问题 更多 >
编程相关推荐