- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写一个用于自动将文件传送到 Cisco 设备的脚本,当设备未配置为 SCP 服务器时,我收到一个错误,导致我的整个脚本终止。
我已经为其他脚本终止异常添加了两个异常,但是当我尝试为这个 SCP 错误添加它时,我收到以下错误:
try:
ssh_client =paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print((time.strftime('%d-%b-%Y %H:%M:%S'))+" - Attempting SSH connection with "+ip)
ssh_client.connect(hostname=ip,username=user,password=passw)
print((time.strftime('%d-%b-%Y %H:%M:%S'))+" - Successfully established SSH connection with "+ip)
scp = SCPClient(ssh_client.get_transport(), progress = progress)
print((time.strftime('%d-%b-%Y %H:%M:%S'))+" - Transferring file to "+ip)
scp.put(src, remote_path=dst)
print((time.strftime('%d-%b-%Y %H:%M:%S'))+" - Successfully transferred "+src+" to "+ip)
ssh_client.close()
print((time.strftime('%d-%b-%Y %H:%M:%S'))+" - Closed SSH session with "+ip)
print("###########")
f = open("scpaudit.txt","a")
f.write(time.strftime('%d-%b-%Y %H:%M:%S')+" "+user+" transferred "+src+" to "+ip)
f.close()
except paramiko.ssh_exception.AuthenticationException:
print("-> ERROR: Auth error for "+user+" on "+ip)
print("#########")
f = open("scpaudit.txt","a")
f.write(time.strftime('%d-%b-%Y %H:%M:%S')+" ERROR: Authentication Error for "+user+" to "+ip)
f.close()
except paramiko.ssh_exception.NoValidConnectionsError:
print("-> ERROR: Unable to connect to "+ip)
print("#########")
f = open("scpaudit.txt","a")
f.write(time.strftime('%d-%b-%Y %H:%M:%S')+" ERROR: Unable to connect to "+ip)
f.close()
当我遇到没有启用 SCP 服务器的设备时,我收到以下错误:
Traceback (most recent call last):
File "scpscript.py", line 100, in <module>
yes_or_no("I confirm that the above information is correct and I would like to proceed. ")
File "scpscript.py", line 93, in yes_or_no
return session()
File "scpscript.py", line 65, in session
scp.put(src, remote_path=dst)
File "/usr/local/lib/python2.7/dist-packages/scp.py", line 158, in put
self._recv_confirm()
File "/usr/local/lib/python2.7/dist-packages/scp.py", line 363, in _recv_confirm
raise SCPException(asunicode(msg[1:]))
scp.SCPException: Administratively disabled.
然后我将以下异常添加到末尾(忍者编辑在 07:15 - 将错误的异常复制到 stackoverflow):
except scp.SCPException:
print("-> SCP administratively disabled on remote device "+ip)
...然后会导致以下错误:
Traceback (most recent call last):
File "scpscript.py", line 100, in <module>
yes_or_no("I confirm that the above information is correct and I would like to proceed. ")
File "scpscript.py", line 93, in yes_or_no
return session()
File "scpscript.py", line 85, in session
except scp.SCPException(asunicode(msg[:])):
AttributeError: 'SCPClient' object has no attribute 'SCPException'
没有想法。 try
中的行是否可以组织得更好?我感谢任何反馈!谢谢。
最佳答案
scp
模块名称和本地 scp
变量之间存在冲突。
一种可能的解决方案是更改变量的名称。按照 ssh_client
模式,您可以使用 scp_client
:
scp_client = SCPClient(ssh_client.get_transport(), progress = progress)
scp_client.put(src, remote_path=dst)
关于python - "' SCPClient ' object has no attribute ' SCPException '"试图处理来自 Paramiko 的 SCP 模块的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57289278/
我不是 C 程序员。有什么想法吗? 这是我尝试过的安装命令: pip install paramiko sudo pip install paramiko 输出: src/_fastmath.c:15
Importing paramiko throws following exception on Python3. Traceback (most recent call last): File
我正在编写一个 Python 脚本,需要下载远程 xml 文件来解析它。 我正在使用 paramiko。 这是脚本: def copyFile(ip, user, pwd, remotePath, l
好的,所以我正在尝试在我的 python 脚本中实现 paramiko。 目的是连接同一局域网内的另一台PC,通过python执行命令。 我的 python 版本: Python 2.7.6 (def
我正在调试一些代码,这将导致我不断地登录/退出一些外部 sftp 服务器。有谁知道如果代码中出现非 paramiko 异常,paramiko 是否会自动关闭外部服务器上的 ssh/sftp sessi
我不断收到以下错误: Traceback (most recent call last): File "/home/d/workspace/paramiko/connect_test/main.p
我正在尝试通过 SSH 从 Python 远程执行命令,在这种特殊情况下需要将 stdin 重定向到/dev/null。 也就是说,与使用带有 -n 标志的 OpenSSH 客户端相同: ssh -n
当我尝试打开 mysql 工作台时,它显示“导入错误:没有名为 paramiko 的模块;操作失败:无法启动 SSH 隧道管理器”,尽管我已经安装了 paramiko。我正在使用 python 2.7
我正在尝试使用 paramiko 通过 netcat 反弹 SSH session : MyLocalMachine ----||----> MiddleMachine --(netcat)-->
我目前正在开发一个程序,该程序尝试联系运行 Cisco IOS 的众多路由器以获取其当前配置。我正在尝试使用 Paramiko 模块的 SSHClient 来实现这一点目的: def get_conf
我有基于 paramiko 模块的 python 2.7 代码,我想将其移植到 python 3.3,但我似乎找不到可以工作的 paramiko 版本或合适的替代版本。 我需要该模块在 Windows
我正在尝试运行使用 SSHLibrary 的机器人框架测试用例。我已经安装了所有必需的库(在本例中为 paramiko)。但我仍然收到此错误。 我得到的错误是: Error in file '/opt
有什么方法可以在后台运行 mysql 命令或保持连接事件一段时间,以便可以对其执行查询。可以用nohup来实现吗?如果是,怎么办? 最佳答案 是的,你可以用ajax来做到这一点 使用Nohup你可以做
我正在尝试在 python 中使用 paramiko 执行一个简单的代理命令。 基本上我正在尝试复制此 ssh 命令的行为: ssh -i ~/.ssh/destination_key user@de
This question already has answers here: Pass input/variables to command/script over SSH using Python
Paramiko 支持基于证书的身份验证吗? connect 方法中的 key_filename 提到它同时支持私钥和证书,这里的证书是指基于证书的身份验证吗? key_filename (str)
我刚刚尝试与 paramiko 进行 ssh 连接。一切看起来都很好,但在最后一步,当调用 close() 方法断开客户端连接时。 这是我的脚本: #!/usr/bin/python import p
上下文 如果有一个连接到服务器的脚本,然后 curl 本地主机以获取我需要的信息 问题 我的问题是,我需要从大约 200 台服务器获取信息,我使用的方法大约需要 15 分钟才能完成,这还不错,但我想做
我在尝试关闭 Paramiko SFTP 连接时遇到问题。即使我调用关闭连接仍然挂起,我通过运行 netstat (Windows) 检查: netstat -an | find ":22" 和pyt
localpath = 'U:\\' utime = sftp.stat("/TestBTEC/").st_mtime last_modified = datetime.fromtimestamp(u
我是一名优秀的程序员,十分优秀!