Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:应为str、bytes或os.PathLike对象,而不是_io.BufferedReader_Python_Ftplib - Fatal编程技术网

Python TypeError:应为str、bytes或os.PathLike对象,而不是_io.BufferedReader

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

我正在尝试使用以下代码(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(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