Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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 使用套接字发送图像而不保存图像_Python_Python 3.x_Sockets - Fatal编程技术网

Python 使用套接字发送图像而不保存图像

Python 使用套接字发送图像而不保存图像,python,python-3.x,sockets,Python,Python 3.x,Sockets,我尝试使用已保存的图像文件(已工作),然后尝试只发送图像的字节(我不想保存图像),但出现错误: TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO 这是我的代码: frame = self.newFrame() fm = BytesIO() frame.save(fm, 'jpeg') with open(fm, 'rb') as f: while True: si = f.read

我尝试使用已保存的图像文件(已工作),然后尝试只发送图像的字节(我不想保存图像),但出现错误:

TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO
这是我的代码:

frame = self.newFrame()
fm = BytesIO()
frame.save(fm, 'jpeg')
with open(fm, 'rb') as f:
    while True:
        si = f.read(1024)
        if si:
            self.conn.send(si)
        else:
            break

你们怎么能看到我试图使用BytesIO演示文件,但不是像我想的那样工作。。。我不知道如何在不使用
open()
命令的情况下发送字节。

您不需要打开
fm
,因为它已经在内存中了。只需使用
fm.seek(0)
搜索缓冲区的开头,并像您已经做的那样将其写入套接字