Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 帕拉米科频道从未做好接收准备_Python_Git_Python 3.x_Ssh_Paramiko - Fatal编程技术网

Python 帕拉米科频道从未做好接收准备

Python 帕拉米科频道从未做好接收准备,python,git,python-3.x,ssh,paramiko,Python,Git,Python 3.x,Ssh,Paramiko,我试图让git命令与paramiko服务器一起工作。我确实收到了git receive pack命令,但无法从通道接收任何数据 class Server(paramiko.ServerInterface): def __init__(self): self.event = threading.Event() def check_channel_request(self, kind, chanid): if kind == 'session':

我试图让git命令与paramiko服务器一起工作。我确实收到了
git receive pack
命令,但无法从通道接收任何数据

class Server(paramiko.ServerInterface):
    def __init__(self):
        self.event = threading.Event()

    def check_channel_request(self, kind, chanid):
        if kind == 'session':
            return paramiko.OPEN_SUCCEEDED
        return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED

    def check_channel_shell_request(self, channel):
        self.event.set()
        return True

    def check_channel_exec_request(self, channel, command):
        command = command.split(' ')
        if command[0] not in ['git-receive-pack', 'git-upload-pack']:
            return False
        command[-1] = '/home/remco/Downloads/git'
        self.event.set()
        t = threading.Thread(target=git.command, args=[command, channel])
        t.start()
        return True

    def check_global_request(self, kind, msg):
        return super().check_global_request(kind, msg)

    def check_channel_forward_agent_request(self, channel):
        return False

    def check_channel_subsystem_request(self, channel, name):
        return super().check_channel_subsystem_request(channel, name)

    def check_auth_password(self, username, password):
        if True:
            return paramiko.AUTH_SUCCESSFUL
        return paramiko.AUTH_FAILED

    def check_auth_publickey(self, username, key):
        return paramiko.AUTH_SUCCESSFUL

    def get_allowed_auths(self, username):
        return 'password,publickey'

    def check_channel_pty_request(self, channel, term, width, height, pixelwidth,
                                  pixelheight, modes):
        return True



def main():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
    sock.bind((config.config['ssh']['host'], config.config['ssh']['port']))
    sock.listen(1)
    while True:
        conn, addr = sock.accept()
        host_key = paramiko.RSAKey.from_private_key_file(path.expanduser(
            config.config['ssh']['keyfile']))
        trans = transport.Transport(conn)
        trans.load_server_moduli()
        trans.add_server_key(host_key)
        server = Server()
        trans.start_server(server=server)
        server.event.wait(1)
git.command是以下函数:

@logging.logger()
def command(command, channel):
    proc = subprocess.Popen(command, stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    while True:
        print(channel.recv_ready())
    result = ''

    while True:
        r_ready, w_ready, x_ready = select.select(
            [channel, proc.stdout, proc.stderr], [proc.stdin], [])
        if channel in r_ready:
            logging.info('in')
            data = channel.recv(1024)
            if data:
                logging.info(data)
                proc.stdin.write(data)
        if proc.stdout in r_ready:
            print('out')
            data = proc.stdout.read(1)
            result += data.decode('utf-8')
#            print(data)
            channel.sendall(data)
        if proc.stderr in r_ready:
            print('err')
            data = proc.stderr.read(1)
            if data:
                print(data)
                channel.sendall_stderr(data)
            else:
                break
    print(result)

    print('done')
    proc.stdin.close()
    proc.stdout.close()
    proc.stderr.close()
问题是
channel.recv_ready()
永远不会
True
,而
channel.recv(n)
会导致无限等待。
@logging.logger()。它打印以下内容:

Called command with *(['git-receive-pack', '/home/remco/Downloads/git'], <paramiko.Channel 1 (open) window=2097152 -> <paramiko.Transport at 0x2611ed10 (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>) **{}
用*(['git-receive-pack','/home/remco/Downloads/git'],>)调用命令***{
我是否忘记了在接收数据之前需要做的事情