免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8139 | 回复: 5
打印 上一主题 下一主题

pxssh超时错误问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-03-05 16:13 |只看该作者 |倒序浏览
代码如下:
----------------------
import pxssh
import getpass
try:                                                            
        s = pxssh.pxssh()
        hostname = raw_input('hostname: ')
        username = raw_input('username: ')
        password = getpass.getpass('password: ')

        s.force_password = True
        s.login (hostname, username, password)
        s.sendline ('uptime')  # run a command
        s.prompt()             # match the prompt
        print s.before         # print everything before the prompt.
        s.sendline ('ls -l')
        s.prompt()
        print s.before
        s.sendline ('df')
        s.prompt()
        print s.before
        s.logout()
except pxssh.ExceptionPxssh, e:
        print "pxssh failed on login."
        print str(e)
--------------------------------
错误:
Traceback (most recent call last):
  File x-pxssh.py, line 10, in <module>
    s.login (hostname, username, password)
  File /usr/lib/python2.5/site-packages/pxssh.py, line 243, in login
    if not self.synch_original_prompt():
  File /usr/lib/python2.5/site-packages/pxssh.py, line 134, in synch_original_prompt
    self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt
  File /usr/lib/python2.5/site-packages/pexpect.py, line 824, in read_nonblocking
    raise TIMEOUT ('Timeout exceeded in read_nonblocking().')
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().

通过独立的ssh客户端登陆到我的ssh服务器上的时候是很快的,不存在超时的问题。
大伙看看是啥原因?

论坛徽章:
0
2 [报告]
发表于 2010-03-09 00:03 |只看该作者

论坛徽章:
0
3 [报告]
发表于 2010-03-09 09:26 |只看该作者
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
根据错误信息,是由于pexpect模块的TIMEOUT错误,你需要处理一下,可以参考。
http://www.ibm.com/developerworks/cn/linux/l-cn-pexpect1/
由于是pxssh封装了pexpect库,你需要查看pxssh手册的login函数是怎么处理TIMEOUT错误的。

论坛徽章:
0
4 [报告]
发表于 2010-03-10 22:00 |只看该作者

论坛徽章:
0
5 [报告]
发表于 2012-07-27 11:29 |只看该作者

论坛徽章:
0
6 [报告]
发表于 2012-07-27 11:38 |只看该作者
I don't know if anyone ever got back to you with a fix, but for me the
fix was really simple.

I just added a self.sendline() and a time.sleep(0.5) right before the
first read_nonblocking() call within synch_original_prompt

The reason is that you have to have stuff in the buffer in order to
read it. In the case that they programmed for originally,
**something** exists in their prompt (probably a space) after the $ or
#. In my case (and probably yours) the last thing on the prompt
**is** the $ or #, causing the buffer to be non-existent when the
first read_nonblocking() happens. So all we do is put something there
before the read.

Why not just get rid of the first read since it is just "clearing the
buffer" anyway? Because then, although it would now work for us, it
would no longer work for the original programmers.

- Jinno


解释比较清楚
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP