OSError: [WinError 10022] An invalid argument was supplied | Python Socket Error
I was working on socket programming. The code was running fine on Python 2 but it was throwing an error while running on Python 3 version.
Error is as follows:
>>py server.py Traceback (most recent call last): File "server.py", line 20, in <module> c, cAddr = s.accept() File "C:\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 212, in accept fd, addr = self._accept() OSError: [WinError 10022] An invalid argument was supplied
This is the exception thrown by the Operating System while executing socket program on Windows OS.
It is mandatory to add
- “s” is the socket object.
- 2o is the maximum number of queued connections. You can set any number as per your requirement.
I had missed this line to add in my socket program. Because of this, my program was crashing.
After adding this line of code just before the
s.accept(), my issue is solved.
How to debug WinError in Socket Programming?
It is not easy to debug any socket programming errors.
WinError 10022 is for not passing valid arguments to the socket. This is just one example. There are many socket errors you will come across. Each error code has different meaning. You can check the error codes and their meanings on Official Microsoft website.
To avoid this crash, it is always good practice to add exception handling in any socket program you write.
If you are getting any error in your socket program and not able to fix it, write in the comment. I will help you on my best.