try:
print('\n\n下发请求,重启路由器:')
reboot_response = urllib.request.urlopen(reboot_req)
except ConnectionAbortedError as e:
print("出现异常了")
print(traceback.print_exc())
else:
reboot_page = reboot_response.read()
控制台输出如下:
下发请求,重启路由器:
Traceback (most recent call last):
File "D:/AutoTest/Router.py", line 72, in <module>
reboot_page = reboot_response.read()
File "D:\Python37\lib\http\client.py", line 457, in read
s = self.fp.read()
File "D:\Python37\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] 您的主机中的软件中止了一个已建立的连接。
没有执行 except 中的代码???