代码之家  ›  专栏  ›  技术社区  ›  C.med

OSError:[Errno 22]参数无效(Paramiko)

  •  1
  • C.med  · 技术社区  · 7 年前

    我尝试了不同的堆栈溢出解决方案,但仍然有相同的问题。

    localpath = os.path.join(os.sep, 'Users', 'me', 'Desktop', 'ELK', 'PM_XML')
    serverpath = r"***/****/***"
    def sftp():
        ip=ipAddr.get()
        while True:
            current_time = time.time()
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            ssh.connect(ip,username="root",password="root")
            sftp = ssh.open_sftp()
            for element in sftp.listdir(serverpath):
                if element.endswith(".xml"):
                    creation_time = sftp.stat(serverpath+element).st_mtime
                    if (current_time+3400 - creation_time) / (3600) <= 1:
                        sftp.get(serverpath+element,os.path.join(os.sep,localpath,element))
            sftp.close()
            ssh.close()
    

    我得到这个错误:

    Traceback (most recent call last):
      File "<stdin>", line 5, in <module>
      File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\paramiko\sftp_client.py", line 801, in g
    et
        with open(localpath, "wb") as fl:
    OSError: [Errno 22] Invalid argument: '\\Users\\me\\Desktop\\ELK\\PM_XML\\A2018-10-18T11:03:00+02:00-2018-10-18T11:04:00
    +02:00_user-67-0-test-vm2.lk.fr.xml'
    

    A2018-10-18T11:03:00+02:00-2018-10-18T11:04:00+02:00\u用户-67-0-test-vm2.lk.fr.xml'

    任何处理这个文件名的建议,因为我想保持服务器上使用的相同名称。

    由Martin Prikryl解决 建议将冒号“:”替换为“\”

    element.replace(":","_")
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Community Mohan Dere    5 年前

    : ),以及其他特殊字符。

    Naming Conventions :

    使用当前代码页中的任何字符作为名称,包括Unicode字符和扩展字符集(128255)中的字符,但以下字符除外:

    • ...

    • :(冒号)

    • ...


    你对此无能为力。