首页新闻找找看学习计划

如何解决报错中的无效参数

0
[待解决问题]

from socket import *
from threading import Thread

def GetData(udpSocket):
while True:
recv_content = udpSocket.recvfrom(1024)
print(">>>:%s + %s" % (recv_content[0], recv_content[1]))

def PostData(udpSocket, Addr):
while True:
content = input('>>>输入内容:')
udpSocket.sendto(content.encode('gb2312'), Addr)

def main():
udpSocket = socket(AF_INET, SOCK_DGRAM)
ip = input("请输入目标IP地址:")
MuBiaoDuanKou = int(input("请输入目标端口:"))
#BenDiDuanKou = int(input("请输入本地端口:"))
Addr = (ip, MuBiaoDuanKou)
#bindAddr = socket.bind('', BenDiDuanKou)
t1 = Thread(target=GetData,args=(udpSocket,))
t2 = Thread(target=PostData,args=(udpSocket,Addr))

t2.start()
t1.start()

t2.join()
t1.join()

if name == 'main':
main()

》》》》运行时报错:
Traceback (most recent call last):
File "D:\PyCharm\Py Interpreter\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "D:\PyCharm\Py Interpreter\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "E:/Py Code/test/test.py", line 7, in GetData
recv_content = udpSocket.recvfrom(X)
OSError: [WinError 10022] 提供了一个无效的参数。

A-handsome-cxy的主页 A-handsome-cxy | 菜鸟二级 | 园豆:202
提问于:2018-10-12 15:29
< >
分享
所有回答(2)
0

你这代码贴的...真没有回答的欲望,粘贴到编辑器还要重新排格式

会发光 | 园豆:266 (菜鸟二级) | 2018-10-12 15:34
 1 from socket import *
 2 from threading import Thread
 3 
 4 
 5 def GetData(udpSocket):
 6     while True:
 7         recv_content = udpSocket.recvfrom(1024)
 8         print(">>>:%s + %s" % (recv_content[0], recv_content[1]))
 9 
10 
11 def PostData(udpSocket, Addr):
12     while True:
13         content = input('>>>输入内容:')
14         udpSocket.sendto(content.encode('gb2312'), Addr)
15 
16 
17 def main():
18     udpSocket = socket(AF_INET, SOCK_DGRAM)
19     ip = input("请输入目标IP地址:")
20     MuBiaoDuanKou = int(input("请输入目标端口:"))
21     #BenDiDuanKou = int(input("请输入本地端口:"))
22     Addr = (ip, MuBiaoDuanKou)
23     #bindAddr = socket.bind('', BenDiDuanKou)
24     t1 = Thread(target=GetData,args=(udpSocket,))
25     t2 = Thread(target=PostData,args=(udpSocket,Addr))
26 
27     t2.start()
28     t1.start()
29 
30     t2.join()
31     t1.join()
32 
33 if __name__ == '__main__':
34     main()

 

支持(0) 反对(0) A-handsome-cxy | 园豆:202 (菜鸟二级) | 2018-10-12 15:40

@A-handsome-cxy: 

》》》》运行时报错:
Traceback (most recent call last):
File "D:\PyCharm\Py Interpreter\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "D:\PyCharm\Py Interpreter\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "E:/Py Code/test/test.py", line 7, in GetData
recv_content = udpSocket.recvfrom(X)
OSError: [WinError 10022] 提供了一个无效的参数。

看倒数第二行,udpSocket.recvfrom(X) 你代码提供的是1024 这个参数是不对的,具体提交什么类型、什么格式的参数,看要求

支持(0) 反对(0) 会发光 | 园豆:266 (菜鸟二级) | 2018-10-12 15:50

@会发光: 我开始以为是传参的问题,因此我加了一个参数X,后面依然不对,我就直接写的1024

他的报错是这样的:

Traceback (most recent call last):
  File "D:\PyCharm\Py Interpreter\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "D:\PyCharm\Py Interpreter\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "E:/Py Code/test/test.py", line 7, in GetData
    recv_content = udpSocket.recvfrom(1024)
OSError: [WinError 10022] 提供了一个无效的参数。

但是我看的教程就是传的1024并且我之前写的时候也没错啊

支持(0) 反对(0) A-handsome-cxy | 园豆:202 (菜鸟二级) | 2018-10-12 15:54
0

纯文本代码!

Eysa | 园豆:81 (初学一级) | 2018-10-12 15:37
 1 from socket import *
 2 from threading import Thread
 3 
 4 
 5 def GetData(udpSocket):
 6     while True:
 7         recv_content = udpSocket.recvfrom(1024)
 8         print(">>>:%s + %s" % (recv_content[0], recv_content[1]))
 9 
10 
11 def PostData(udpSocket, Addr):
12     while True:
13         content = input('>>>输入内容:')
14         udpSocket.sendto(content.encode('gb2312'), Addr)
15 
16 
17 def main():
18     udpSocket = socket(AF_INET, SOCK_DGRAM)
19     ip = input("请输入目标IP地址:")
20     MuBiaoDuanKou = int(input("请输入目标端口:"))
21     #BenDiDuanKou = int(input("请输入本地端口:"))
22     Addr = (ip, MuBiaoDuanKou)
23     #bindAddr = socket.bind('', BenDiDuanKou)
24     t1 = Thread(target=GetData,args=(udpSocket,))
25     t2 = Thread(target=PostData,args=(udpSocket,Addr))
26 
27     t2.start()
28     t1.start()
29 
30     t2.join()
31     t1.join()
32 
33 if __name__ == '__main__':
34     main()
 1 》》》输出:
 2 
 3 
 4 Traceback (most recent call last):
 5   File "D:\PyCharm\Py Interpreter\lib\threading.py", line 917, in _bootstrap_inner
 6     self.run()
 7   File "D:\PyCharm\Py Interpreter\lib\threading.py", line 865, in run
 8     self._target(*self._args, **self._kwargs)
 9   File "E:/Py Code/test/test.py", line 7, in GetData
10     recv_content = udpSocket.recvfrom(1024)
11 OSError: [WinError 10022] 提供了一个无效的参数。
支持(0) 反对(0) A-handsome-cxy | 园豆:202 (菜鸟二级) | 2018-10-12 15:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册