繁体   English   中英

WinError 10060 尝试使用 Python PySFTP 模块连接到远程服务器时出错

[英]WinError 10060 Error when trying to connect to remote server using Python PySFTP module

我正在尝试使用以下代码连接到远程服务器并列出路径内的文件:

import pysftp

myHostname = "myhostname.com"
myPort = <someportnumber>
myUsername = "<valid username>"
myPassword = "<valid password>"

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts= cnopts, port=myPort) as sftp:
    print("Connection succesfully established ... ")

    sftp.chdir('/logs/dev')

    # Obtain structure of the remote directory
    directory_structure = sftp.listdir_attr()

    # Print data
    for attr in directory_structure:
        print(attr.filename, attr)

但是当我运行它时,它无法建立连接。 它抛出以下异常:

Traceback (most recent call last):
  File "c:/Users/611841191/Documents/SFTP File Download/SFTPFileDownload.py", line 11, in <module>
    with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts= cnopts, port=myPort) as sftp:
  File "C:\Users\611841191\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py", line 140, in __init__
    self._start_transport(host, port)
  File "C:\Users\611841191\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py", line 176, in _start_transport
    self._transport = paramiko.Transport((host, port))
  File "C:\Users\611841191\AppData\Roaming\Python\Python38\site-packages\paramiko\transport.py", line 415, in __init__
    raise SSHException(
paramiko.ssh_exception.SSHException: Unable to connect to <myhostname.com>: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond 

任何人都可以帮我解释为什么抛出这个异常,因为我尝试使用其他远程服务器并且代码似乎对他们来说工作正常? 该代码仅对一个特定的远程服务器抛出异常。

如果您的代码无法使用某种协议(在这种情况下为 SFTP)连接到某个地方,那么首先要测试的是,您是否可以使用运行代码的同一台机器上的任何现有 GUI/命令行客户端使用相同的协议进行连接。

如果这也不起作用,那么您没有编程问题,而是一个简单的网络连接问题。

如果您需要帮助解决问题,请将 go 发送至超级用户服务器故障

urllib.error.URLError:

[英]urllib.error.URLError: <urlopen error [WinError 10060] using urllib.request.urlretrieve() on Windows 10 with Python3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM