首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pexpect不能正常工作

pexpect不能正常工作
EN

Stack Overflow用户
提问于 2015-10-29 18:54:23
回答 1查看 3.1K关注 0票数 0

我正在尝试将一些文件从远程服务器复制到我的机器上。当被请求时,我在pexpect中使用spawn进行身份验证。我部分成功地从服务器下载了文件。问题是在完成下载之前抛出了一个异常“ETAException pexpect.ExceptionPexpect: ExceptionPexpect() in > ignored”

下面是我的代码:

代码语言:javascript
复制
def doScp(user,password,host,remotepath,localpath,files):
try:
    print files
    child = pexpect.spawn('sudo scp -C %s:%s%s %s' % (host, remotepath, files, localpath))
    child.logfile = sys.stdout
    print 'scp -C %s:%s%s %s' % (host, remotepath, files, localpath)
    i = child.expect(['assword', r"yes/no"], timeout=20)
    if i == 0:
        print "Value of I is Zero\n"
        child.sendline(password)
        j = child.expect(['yes/no'],timeout=20)
        if j == 0:
            child.sendline("yes")
        child.expect(pexpect.EOF, timeout=None)
    elif i == 1:
        child.sendline("yes")
        child.expect("assword", timeout=20)
        child.sendline(password)
        child.expect(pexpect.EOF, timeout=None)
    child.interact()
except pexpect.ExceptionPexpect, e:
    return False
EN

回答 1

Stack Overflow用户

发布于 2015-11-02 20:39:58

我自己找到了答案。问题出在超时。我没有给超时,现在它工作正常:)这是我的代码

代码语言:javascript
复制
def doScp(user,password,host,remotepath,localpath,files):
    try:
        print files
        child = pexpect.spawn('sudo scp -C %s:%s%s %s' % (
                              host, remotepath, files, localpath))
        child.logfile = sys.stdout
        print 'scp -C %s:%s%s %s' % (host, remotepath, files, localpath)
        i = child.expect(['assword', r"yes/no"], timeout=None)
        if i == 0:
            print "Value of I is Zero\n"
            child.sendline(password)
            j = child.expect(['yes/no'],timeout=None)
            if j == 0:
                child.sendline("yes")
            child.expect(pexpect.EOF, timeout=None)
        elif i == 1:
            child.sendline("yes")
            child.expect("assword", timeout=None)
            child.sendline(password)
            child.expect(pexpect.EOF, timeout=None)
        child.interact()
    except pexpect.ExceptionPexpect, e:
        return False
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33412277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档