【问题标题】:Getting error while connecting SSH using python使用 python 连接 SSH 时出错
【发布时间】:2019-04-06 02:51:28
【问题描述】:

我正在尝试使用 python 连接我的一台在 Windows 中运行的 Virtual CentOS 机器。

我已经安装了 paramiko 模块来做这件事。但低于错误

C:\Users\xxxx\PycharmProjects\xxxx\venv\lib\site-packages\paramiko\kex_ecdh_nist.py:39: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  m.add_string(self.Q_C.public_numbers().encode_point())
C:\Users\xxx\PycharmProjects\xxxx\venv\lib\site-packages\paramiko\kex_ecdh_nist.py:96: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point
  self.curve, Q_S_bytes
C:\Users\xxxx\PycharmProjects\xxxx\venv\lib\site-packages\paramiko\kex_ecdh_nist.py:111: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  hm.add_string(self.Q_C.public_numbers().encode_point())

下面是我的代码:

import paramiko

ssh = paramiko.client.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
    ssh.connect('10.xx.xx.xxx', username='root', password='xxxxx')
except paramiko.SSHException:
    print("Connection Failed")
    quit()

stdin, stdout, stderr = ssh.exec_command("ls /etc/")

for line in stdout.readlines():
    print
    line.strip()
ssh.close()

我使用 PyCharm 2018.3 社区版

请让我知道我在这里做错了什么

【问题讨论】:

    标签: python windows ssh centos connect


    【解决方案1】:

    这些不是错误,这些是 paramiko 抛出的警告,他们需要更新代码以使用更多最新参数。您的代码仍应运行。最好的办法是查看是否有更新版本或向 paramiko 包的作者提出问题。

    【讨论】:

    • 谢谢..让我检查一下...因为代码没有给我任何输出。
    • @Sandy 只需将循环中的 2 行捆绑为 1: print(line.strip())
    【解决方案2】:

    Paramiko 使用的方法已弃用。您应该考虑将 Python 降级到较低版本或下载更新(如果存在)版本的 Paramiko

    【讨论】:

      猜你喜欢
      • 2019-05-28
      • 2021-03-05
      • 2015-01-17
      • 2011-07-15
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多