简体   繁体   English

为什么我的 Python 程序不能上传我的文件?

[英]Why won't my Python program upload my file?

I have a simple script to upload an Excel file to an external sftp server using Python 3 and pysftp library ( https://pysftp.readthedocs.io/en/release_0.2.9/ ).我有一个简单的脚本可以使用ZA7F5F55F355426B927411FC9231B5631B56382173Z 3和PYSFTP PRIBLY( Z5E056C5E056C5E1C5E1C5E1C5E1C500A.4BBHEREN.4BBHERES )上传ZC1D81AF583584B4E9D9369D9369D936910DED8FDCZ文件。

When I run it, I get aa vague error:当我运行它时,我得到一个模糊的错误:

An error occurred Exception ignored in: <function Connection.__del__
at 0x0000014B03749EA0> Traceback (most recent call last):   File
"H:\Python310\lib\site-packages\pysftp\__init__.py", line 784, in
close
    if self._sftp_live: AttributeError: 'Connection' object has no attribute

Here is my little script:这是我的小脚本:

import pysftp

try:
    with pysftp.Connection('xyz.edu', username='test', password='xyz') as sftp:

        with sftp.cd('/data'):
            sftp.put('/pycode/DataSpring.xlsx')
except:
    print("An error occurred")

else:
    print("File uploaded successfully")

I copied & pasted the server, username, and password into WinSCP and it worked fine.我将服务器、用户名和密码复制并粘贴到 WinSCP 中,效果很好。

The file path for both remote and local exist and the file does exist and is not locked or anything.远程和本地的文件路径都存在,并且文件确实存在并且没有被锁定或任何东西。

Is there something I missing?有什么我想念的吗?

Pysftp has known issues with handling the host key. Pysftp 已知处理主机密钥的问题。 You can find the solution to your problem in the answers to this post: Verify host key with pysftp您可以在这篇文章的答案中找到问题的解决方案: 使用 pysftp 验证主机密钥

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

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