【问题标题】:Same command sent locally works, but not when sent remotely?本地发送的相同命令有效,但远程发送时无效?
【发布时间】:2021-01-30 11:10:06
【问题描述】:

我想知道是否有人可以提供帮助,我使用以下图形命令针对同一主机..

当我直接登录到主机时,它执行得很好。 (忽略标准的 graph_cli 错误)

pi@raspberrypi:~ $ graph shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output shared/zzzz07.png

/usr/local/lib/python2.7/dist-packages/pandas/plotting/_converter.py:129: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters.

To register the converters:
        >>> from pandas.plotting import register_matplotlib_converters
        >>> register_matplotlib_converters()
  warnings.warn(msg, FutureWarning)

但是当我尝试使用这个 ssh 命令通过另一台机器将它发送到同一主机时,(适用于其他命令)

root@MiOS_54321:/# ssh -i /etc/dropbear/dropbear_rsa_host_key pi@192.168.1.37 graph shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --output shared/zzzz07.png

我收到此错误消息

Traceback (most recent call last):
  File "/usr/local/bin/graph", line 11, in <module>
    sys.exit(main.main())
  File "/usr/local/lib/python2.7/dist-packages/graph_cli/main.py", line 10, in main
    graphs = get_graph_defs(args)
  File "/usr/local/lib/python2.7/dist-packages/graph_cli/graph.py", line 171, in get_graph_defs
    graphs, globals = read_chain(args)
  File "/usr/local/lib/python2.7/dist-packages/graph_cli/graph.py", line 194, in read_chain
    data = stdin.buffer.read()
AttributeError: 'file' object has no attribute 'buffer'

有没有人知道问题/修复可能是什么?

【问题讨论】:

    标签: python linux ssh graph


    【解决方案1】:

    看起来远程主机正在运行 Python 2,而您的本地主机正在运行 Python 3。在 Python 3 中,sys.stdin 对象具有 buffer 属性:

    $ python3
    [...]
    >>> import sys
    >>> sys.stdin.buffer
    <_io.BufferedReader name='<stdin>'>
    

    但是这个属性在 Python 2 中不存在:

    $ python2
    [...]
    >>> import sys
    >>> sys.stdin.buffer
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'file' object has no attribute 'buffer'
    

    看起来您正在运行的代码需要 Python 3。如果您使用例如显式运行它,远程主机可能确实有 Python3 可用。 python3pip3 等,但这是您必须检查的内容。

    【讨论】:

    • 嗨,谢谢,但请原谅这个可能很愚蠢的问题——但命令不是在同一设备上运行吗?一条路由直接发送,而另一条通过远程机器调用/发送(目标始终相同)?
    • 我可能误读了你的问题,当你说“当我尝试从另一台机器远程发送它时”;我没有意识到您针对的是同一主机。无论如何,问题仍然相同(python3 vs python2),但这可能是由于您的环境中的某些问题。您能否更新您的问题以在本地显示 which graph 的输出,并在远程执行时显示相同的命令?
    • 谢谢 - 我已经更新了它,希望它更清晰。并且是的,确认目标始终是同一个主机 - 它只是在第二个示例中,我试图在我的时候调用它m 在另一台机器的命令行(通过 ssh)。
    【解决方案2】:

    graph_cli (https://github.com/mcastorina/graph-cli/issues/39) 的所有者为我提供了答案..

    graph-cli 尝试检测数据是否正在通过管道传输到其中 链接功能。因此,当您从交互式会话中运行它时, isatty() 是真的。当您从非交互式 ssh 命令执行时, isatty() 是假的。这就是它发生的原因。

    如果你运行 echo | 也会发生同样的情况图 ....

    您应该尝试的完整 ssh 命令是:

    ssh -t -i /etc/dropbear/dropbear_rsa_host_key pi@192.168.102.37 '图 shared/feed.csv -y 9,10 --ylabel Temp --title CabinTemp --figsize 1600x1000 --输出共享/zzzz08.png'

    【讨论】:

      猜你喜欢
      • 2012-07-16
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-30
      相关资源
      最近更新 更多