Windows WinError 10038尝试对非套接字的对象执行操作
我正在为我的domotica系统制作一个连接系统,但我遇到了一个无法解决的错误。 这是我的剧本:Windows WinError 10038尝试对非套接字的对象执行操作,windows,sockets,python-3.x,Windows,Sockets,Python 3.x,我正在为我的domotica系统制作一个连接系统,但我遇到了一个无法解决的错误。 这是我的剧本: import insteon import time insteon.connect('10.20.0.195', 9761) while 1: insteon.send('x10', 'N', '10', 'on') time.sleep(5) insteon.send('x10', 'N', '10', 'off') 模块insteon: #!/usr/bin/env
import insteon
import time
insteon.connect('10.20.0.195', 9761)
while 1:
insteon.send('x10', 'N', '10', 'on')
time.sleep(5)
insteon.send('x10', 'N', '10', 'off')
模块insteon:
#!/usr/bin/env python
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def connect(ip, port):
import socket
s.connect((ip, port))
def close():
import socket
s.close()
def send(prot, house, unit, action):
import socket
import binascii
import time
import sys
if prot == 'x10':
units = {'1': '6', '2': 'E', '3': '2', '4': 'A', '5': '1', '6': '9', '7': '5', '8': 'D', '9': '7', '10': 'F', '11': '3', '12': 'B', '13': '0', '14': '8', '15': '4', '16': 'C'}
houses = {'A': '6', 'B': 'E', 'C': '2', 'D': 'A', 'E': '1', 'F': '9', 'G': '5', 'H': 'D', 'I': '7', 'J': 'F', 'K': '3', 'L': 'B', 'M': '0', 'N': '8', 'O': '4', 'P': 'C'}
unitcode = units[unit]
housecode = houses[house]
smessage1 = str('0263') + str(housecode) + str(unitcode) + str('00')
if action == 'on':
smessage2 = str('0263') + str(housecode) + str('280')
elif action == 'off':
smessage2 = str('0263') + str(housecode) + str('380')
else:
sys.exit("Wrong action")
elif prot == 'insteon':
if action == 'on':
SMESSAGE1 = str('0262') + str(id) + str('0011ff')
elif action == 'off':
SMESSAGE1 = str('0262') + str(id) + str('001300')
else:
sys.exit("Wrong choice")
message1 = binascii.unhexlify(smessage1)
if prot == 'x10':
message2 = binascii.unhexlify(smessage2)
s.send(message1)
time.sleep(1)
if prot == 'x10':
s.send(message2)
time.sleep(2)
s.close() # You can't use the socket after this
def receive():
import socket
import binascii
import time
import sys
BUFFER_SIZE = 2048
data = s.recv(BUFFER_SIZE)
data2 = binascii.b2a_hex(data).decode('ascii')
return (data2)
但如果我运行脚本,我会得到:
Traceback (most recent call last):
File "Z:\programeren\repository's\red-cloud2\python backend\x10_server.py", line 8, in <module>
insteon.send('x10', 'N', '10', 'off')
File "Z:\programeren\repository's\red-cloud2\python backend\insteon.py", line 37, in send
s.send(message1)
OSError: [WinError 10038] an operation was attempted on something that is not a socket
回溯(最近一次呼叫最后一次):
文件“Z:\programeren\repository's\red-cloud2\python backend\x10_server.py”,第8行,在
指令发送('x10','N','10','off')
文件“Z:\programeren\repository's\red-cloud2\python backend\insteon.py”,第37行,在send中
s、 发送(消息1)
OSError:[WinError 10038]尝试对非套接字的对象执行操作
我使用python 3编写脚本,并在windows 7 pc上运行此脚本。您的发送函数包括对
套接字的调用。关闭。这将导致套接字上的任何后续操作失败。您的发送函数包括对socket.close的调用。这将导致套接字上的任何后续操作失败。我在PyCharm中从cmd运行flask时遇到此错误。切换到Windows CMD窗口,错误消失了。我在PyCharm中从CMD运行flask时遇到了这个错误。切换到Windows CMD窗口,错误消失。