簡體   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