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

Python TypeError:应为str、bytes或os.PathLike对象,而不是_io.BytesIO,python,python-3.x,sftp,paramiko,pysftp,Python,Python 3.x,Sftp,Paramiko,Pysftp,正在尝试使用ssh将文件从internet上载到我的服务器。有下面的代码,上传本地文件很好,但我不知道还有什么做得到图片字节对象上传 from io import BytesIO import requests import pysftp url = 'https://vignette.wikia.nocookie.net/disney/images/d/db/Donald_Duck_Iconic.png' cnopts = pysftp.CnOpts() cnopts.hostkeys =

正在尝试使用ssh将文件从internet上载到我的服务器。有下面的代码,上传本地文件很好,但我不知道还有什么做得到图片字节对象上传

from io import BytesIO
import requests
import pysftp
url = 'https://vignette.wikia.nocookie.net/disney/images/d/db/Donald_Duck_Iconic.png'

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None 
response = requests.get(url)
netimage = BytesIO(response.content) #imagefromurl

srv = pysftp.Connection(host="12.34.567.89", username="root123",
password="password123",cnopts=cnopts)

with srv.cd('/var/www'): #srvdir
    #srv.put('C:\Program Files\Python36\LICENSE.txt') #local file test
    srv.put(netimage) 

print('Complete')
您需要使用获取类似文件的对象,然后使用以下命令跨数据进行复制:

Paramiko(扩展名为pysftp)不支持直接放入内存中的文件对象

import shutil

with srv.cd('/var/www'):
    with srv.open(image_filename, 'w') as remote_file:
        shutil.copyfileobj(netimage, remote_file)