【问题标题】:Facebook Thrift SSH Frame Size ErrorFacebook Thrift SSH 帧大小错误
【发布时间】:2018-10-23 23:09:07
【问题描述】:

我正在我的机器上运行 Facebook Thrift 服务。我使用了一个示例代码来展示它的工作原理:

import asyncio

from fbnet.command_runner.thrift_client import AsyncioThriftClient

# Import FCR Thrift Types
from fbnet.command_runner_asyncio.CommandRunner import ttypes as fcr_ttypes

# Import FCR Service Client
from fbnet.command_runner_asyncio.CommandRunner.Command import Client as FcrClient

import getpass

# Device Information
hostname = 'my_vm'
username = 'root'
password = getpass.getpass('%s Password: ' % username)

# Destination device
device = fcr_ttypes.Device(hostname=hostname, username=username,     password=password)

async def run(cmd, device):
    async with AsyncioThriftClient(FcrClient, 'x.x.x.x',22 ) as client:
        res = await client.run(cmd, device)
        # type of res is `struct CommandResult`
        print(res.output)

loop = asyncio.get_event_loop()
loop.run_until_complete(run('uname -a', device))

但是我收到以下错误:

帧大小 1397966893 对于 THeaderProtocol Traceback 来说太大(大多数 最近通话最后):
文件“pgm1.py”,第 28 行,在 loop.run_until_complete(run('uname -a', device))
文件“/usr/local/lib/python3.6/asyncio/base_events.py”,第 467 行,在 run_until_complete 返回 future.result()
运行中的文件“pgm1.py”,第 23 行 res = await client.run(cmd, device) thrift.transport.TTransport.TTransportException: 连接关闭

关于如何纠正这个问题的任何想法?

【问题讨论】:

  • 1397966893 = 0x5353482D 的奇怪值从何而来?一些未初始化的变量?
  • 我对thrift一无所知,但是0x5353482D是四个字符“SSH-”,这恰好是ssh服务器连接到它时发送的第一个数据。我的猜测是您正试图在连接到 ssh 服务器的原始 TCP 套接字上启动 thrift。

标签: python facebook ssh thrift


【解决方案1】:

@Kenster 的评论指出了这里的真正问题。

0x5353482D是四个字符“SSH-”,恰好是ssh服务器连接到它时发送的第一个数据

some server implementations that require TFramedProtocol by design。换句话说,它是强制性的,客户端必须使用它,仅仅是因为服务器期望它那样。

知道TFramedProtocol 添加了一个 4 字节标头的人很快就会明白这一点,该标头带有要跟随的数据的帧大小。如果客户端不使用TFramedProtocol,服务器会将前四个数据字节解释为帧大小 - 因此会出现错误消息。

解决方案

将客户端的 TFramedProtocol 添加到 Thrift 传输/协议堆栈。

【讨论】:

  • 如何将 TFramedProtocol 添加到我的代码中。除了上面的文件,我不想更改任何内容。它必须独立运行。
  • 我不知道the whole example comes from Github。你为什么不直接联系它的作者和/或在那里提出问题?
猜你喜欢
  • 2022-12-04
  • 2018-01-16
  • 2014-11-20
  • 2012-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-03
  • 1970-01-01
相关资源
最近更新 更多