python - pysftp 身份验证超时
问题描述
我正在尝试使用 pysftp 自动执行 sftp 传输。目前,我在使用 pysftp 食谱中的代码时遇到身份验证超时错误。这是回溯
我也可以使用登录到服务器sftp -i <id_file> userid@hostname
,因此端口和凭据应该是正确的。
该代码现在正在虚拟机上运行,但可以确认相同的代码在我的本地工作。我正在使用 python 3.7 和最新的 pysftp 库
有什么帮助吗?
import sys
import traceback
import pysftp
# get the arguments passed from cmd
hostname = sys.argv[1]
userid = sys.argv[2]
keyFile = sys.argv[3]
logfile = sys.argv[4]
try:
with pysftp.Connection(hostname, username=userid, private_key = keyFile, log=logfile) as sftp:
print ('Success')
except Exception:
traceback.print_exc()
这是来自 pysftp 的日志
DEB [20210216-03:11:42.696] thr=1 paramiko.transport: starting thread (client mode): 0x58307708
DEB [20210216-03:11:42.697] thr=1 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.7.2
DEB [20210216-03:11:43.672] thr=1 paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_6.4
INF [20210216-03:11:43.673] thr=1 paramiko.transport: Connected (version 2.0, client OpenSSH_6.4)
DEB [20210216-03:11:43.736] thr=1 paramiko.transport: kex algos:['ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEB [20210216-03:11:43.737] thr=1 paramiko.transport: Kex agreed: ecdh-sha2-nistp256
DEB [20210216-03:11:43.737] thr=1 paramiko.transport: HostKey agreed: ssh-rsa
DEB [20210216-03:11:43.738] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20210216-03:11:43.738] thr=1 paramiko.transport: MAC agreed: hmac-sha2-256
DEB [20210216-03:11:43.738] thr=1 paramiko.transport: Compression agreed: none
DEB [20210216-03:11:44.192] thr=1 paramiko.transport: kex engine KexNistp256 specified hash_algo <built-in function openssl_sha256>
DEB [20210216-03:11:44.193] thr=1 paramiko.transport: Switch to new keys ...
DEB [20210216-03:11:44.194] thr=2 paramiko.transport: Host key verified (ssh-rsa)
DEB [20210216-03:11:44.194] thr=2 paramiko.transport: Attempting public-key auth...
DEB [20210216-03:11:44.430] thr=1 paramiko.transport: userauth is OK
DEB [20210216-03:12:14.378] thr=1 paramiko.transport: EOF in transport thread.
解决方案
看起来是服务器的问题。不知何故,代码在身份验证期间超时。使用 paramiko 的 auth_timeout 参数有效。
推荐阅读
- android - 如何在 nativescript 中获取状态栏高度?
- javascript - 如何以两种方式将 Angular Material datepicker 绑定到字符串属性
- java - 使用 ArrayList 实现合并排序的问题
- mysql - Django - 安装 mysqlclient 错误:需要 mysqlclient 1.3.13 或更高版本;你有 0.9.3
- html - 如何使用列名和行名或索引为 R 中的数据表(DT 包)中的单元格的背景着色?
- java - Java 泛型的 Number.valueOf() 实现
- mongodb - Spring Data MongoDB Aggregation pipeline 通过注解
- teamcity - 覆盖 NuGet 包不会更改 .NET 版本
- html - 如何将tinymce的输出代码放入我的容器元素中?
- php - 内存耗尽(最小脚本)