![](/img/trans.png)
[英]python socket programming OSError: [WinError 10038] an operation was attempted on something that is not a socket
[英]I am getting this error in my python code. "OSError: [WinError 10038] An operation was attempted on something that is not a socket"
在我的 python 项目中,我有一个工作服务器。 现在我正在制作客户端,但我不断收到“OSError:[WinError 10038] 尝试对不是套接字的东西进行操作”错误。 我寻找解决方案,但其中大多数涉及人员代码在 while 循环内,他们忘记关闭连接或类似的东西。 我的代码不是那样的,我找不到解决方案。 因此,如果有人知道答案和答案的解释,请提供帮助。 顺便说一句,我正在关注这个教程。
我在第 18 行的 send_message() function 上收到错误消息。
这是我的代码(我有一个 working.kv 文件,但如果需要,我也可以发布它):
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import socket
import threading
kivy.require("1.9.0")
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
class MyRoot(BoxLayout):
def __init__(self):
super(MyRoot, self).__init__()
def send_message(self):
client.send(f"{self.nickname_text.text}: {self.message_text.text}".encode("utf-8"))
def connect_to_server(self):
if self.nickname_text != "":
client.connect((self.ip_text.text, 9999))
message = client.recv(1024).decode("utf-8")
if message == "NICK":
client.send(self.nickname_text.text.encode("utf-8"))
self.send_btn.disabled = False
self.message_text.disabled = False
self.connect_btn.disabled = True
self.ip_text.disabled = True
self.make_invisible(self.connection_grid)
self.make_invisible(self.connect_btn)
thread = threading.Thread(target=self.receive)
thread.start()
def make_invisible(self, widget):
widget.visible = False
widget.size_hint_x = None
widget.size_hint_y = None
widget.height = 0
widget.width = 0
widget.text = ""
widget.opacity = 0
def receive(self):
stop = False
while not stop:
try:
message = client.recv(1024).decode("utf-8")
self.chat_text.text += message + "\n"
except:
print("ERROR")
client.close()
stop = True
class WebChat(App):
def build(self):
return MyRoot()
webChat = WebChat()
webChat.run()
我又做了一些调试,结果发现原因是我安装了错误的 kivy 版本。 感谢所有试图提供帮助的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.