我正在使用新的命令行工具https://github.com/a7i7/HoldMyFile。 但我面临以下功能的一些问题:
def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
s.sendall(content)
s.shutdown(socket.SHUT_WR)
response = ''
while 1:
data = s.recv(1024)
if data == "":
break
data = repr(data)
response = response + data
s.close()
response = response[:-3][1:]
return response
每当我调用netcat(' termbin.com',9999,内容)并且内容中包含大约1 MB的数据时,代码将退出并显示以下错误消息" socket.error: [Errno 32]破管#34; 。
现在如果我使用linux shell发送1 MB的数据
cat data.txt | nc termbin.com 9999
成功发送了所有数据。
我甚至尝试使用python的os.system从linux shell运行相同的命令。仍然遇到破裂的管道错误。请帮我解决这个问题