Python TypeError:应为str、bytes或os.PathLike对象,而不是_io.BufferedReader
我正在尝试使用以下代码(Python 3.6.1 32位,Windows 10 64位)遍历本地计算机上文件夹中的一组文件,并仅将文件名包含“服务区域”的文件上载到我的FTP站点: 但我得到了这个错误:Python TypeError:应为str、bytes或os.PathLike对象,而不是_io.BufferedReader,python,ftplib,Python,Ftplib,我正在尝试使用以下代码(Python 3.6.1 32位,Windows 10 64位)遍历本地计算机上文件夹中的一组文件,并仅将文件名包含“服务区域”的文件上载到我的FTP站点: 但我得到了这个错误: Traceback (most recent call last): File "C:\Users\user\Desktop\Test1.py", line 32, in <module> ftp.storbinary("STOR " + str(i), open(fil
Traceback (most recent call last):
File "C:\Users\user\Desktop\Test1.py", line 32, in <module>
ftp.storbinary("STOR " + str(i), open(file, 'rb'))
TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader
回溯(最近一次呼叫最后一次):
文件“C:\Users\user\Desktop\Test1.py”,第32行,在
storbinary(“STOR”+str(i),打开(文件'rb'))
TypeError:应为str、bytes或os.PathLike对象,而不是_io.BufferedReader
有什么建议吗?我想这与您在
storbinary
中的第二个元素有关。您正试图打开文件
,但它已经是指向您在file=open(local_path,'rb')
行中打开的文件的指针。因此,尝试使用ftp.storbinary(“STOR”+i,file)
Traceback (most recent call last):
File "C:\Users\user\Desktop\Test1.py", line 32, in <module>
ftp.storbinary("STOR " + str(i), open(file, 'rb'))
TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader