telnetlib和"buf = self.sock.recv(50)";错误 [英] telnetlib and "buf = self.sock.recv(50)" error

查看:548
本文介绍了telnetlib和"buf = self.sock.recv(50)";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用telnetlib将简单的telnet脚本连接到Juniper交换机.下面是我的代码:

I am using telnetlib for simple telnet script to Juniper switch. Below is my code:

import telnetlib

HOST = raw_input("Enter host IP address: ")  
USER = raw_input("Enter Username: ")  
PWD = raw_input("Enter Password: ")  
TNT = telnetlib.Telnet(HOST, 23, 10)  
TNT.read_until("login:")  
TNT.write(USER.encode('ascii') + "\n")  
TNT.read_until("Password:")  
TNT.write(PWD.encode('ascii') + "\n")  
TNT.write("set cli screen-length 10000\nconfigure\nshow\nexit\n")  
print (TNT.read_all().decode('ascii'))  
TNT.close()  
raw_input ("Press any Key to Quit: ")  

每当我使用Juniper开关运行该程序时,都会出现此错误:

Whenever I run this program with Juniper switch it gives me this error:

Traceback (most recent call last):  
  File "D:\Python\AuTel Project\Old versions and tials\Telnet (Python 2.7) V1.4.py", line 17, in <module>  
    print (TNT.read_all().decode('ascii'))  
  File "C:\Python27\lib\telnetlib.py", line 325, in read_all  
    self.fill_rawq()  
  File "C:\Python27\lib\telnetlib.py", line 516, in fill_rawq  
    buf = self.sock.recv(50)  
timeout: timed out

我以前在Cisco和Nortel上曾遇到过此问题,但是我可以通过在Cisco上使用"terminal longenght 0"命令以及在Nortel上使用类似命令来克服它.我尝试在Juniper上使用等效命令(设置cli屏幕长度),但仍然遇到相同的错误.我需要知道此错误的含义,原因以及解决方法.

I have faced this problem before with Cisco and Nortel, but I could overcome it with "terminal lenght 0" command on Cisco and similar comand on Nortel. I tried to use the equivalent command on Juniper (set cli screen-length), but I am still getting the same error. I need to know what is the meaning of this error and what is the reason of it, and how to overcome it.

最好的问候,

推荐答案

这对我来说效果很好.

tn.read_very_eager()

请记住,在此之前我们需要提供足够的睡眠时间,以便在读取之前将其记录下来.

Remember, we need to provide sufficient sleep time before this, so that it will be recorded before reading.

这篇关于telnetlib和"buf = self.sock.recv(50)";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆