首页 > 解决方案 > 在 python 中通过套接字发送文件(内存错误)

问题描述

所以我有学校项目,我正在尝试读取文件,然后将其发送到服务器。该代码运行良好,但每当我尝试读取一个大文件时,我都会收到“内存错误”。该错误可能是由于文件的大小而发生的,但我该怎么做才能解决这个问题?

msg = self.encryptor.encrypt(b'#gf ' + open(' '.join(cmd.split(' ')[1:]), 'rb').read())

内存错误

   def getFile(self, cmd):
    msg = self.encryptor.encrypt(b'#gf ' + open(' '.join(cmd.split(' ')[1:]), 'rb').read())
    self.client.send(self.encryptor.encrypt(str(len(msg)).encode()))
    self.client.send(msg)

我在第 2 行有错误。

标签: pythonsocketsmemoryout-of-memory

解决方案


推荐阅读