'I cant figure out why I am getting [WinError 10057] error

I am using the socket module to create a server, And I was just testing my network file, And it seemed to be working, After I made updates to the client file and server file, I try to run the network file again to see if everything's alright, and I get this error [WinError 10057] I can't figure out why am I getting this, Please help, Here is my code

import socket

class Network:
    def __init__(self):
        self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server = "my ip"
        self.port = 5555
        self.addr = (self.server, self.port)
        self.pos = self.connect()
        print(self.pos)

    def getPos(self):
        return self.pos

    def connect(self):
        try:
            self.client.connect(self.addr)
            return self.client.recv(2048).decode()
        except:
            pass

    def send(self, data):
        try:
            self.client.send(str.encode(data))
            return self.client.recv(2048).decode()
        except socket.error as e:
            print(e)

if __name__ == "__main__":
    n = Network()
    print(n.send("Hello, Working! :)"))

This is the output

None
[WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
None


Solution 1:[1]

Never, ever do try: ... except: ... pass unless you absolutely, positively know what you're doing.

  1. Just except: is practically never alright; it will also swallow SystemExit and KeyboardInterrupt, which will make your program hard to interrupt or exit. Instead, to catch all exceptions, except Exception:.
  2. Secondly, don't just wrap a full function in a try: ... except ...: pass. Unless you really do mean that "well whatever happened this function, if it went wrong, I don't care, yolo". (You don't mean that.)

Then, your real exception, from the comment:

File "c:\Users\DEBARKA NASKAR\Desktop\Chess\network.py", line 27, in <module>
  n = Network()
File "c:\Users\DEBARKA NASKAR\Desktop\Chess\network.py", line 9, in init
  self.pos = self.connect()
File "c:\Users\DEBARKA NASKAR\Desktop\Chess\network.py", line 17, in connect
  self.client.connect(self.addr)

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

There is no server process listening on the host and port you've specified (but with your prior code you could have never known since you just swallowed the error and yolo-ed forward).

You will need a server process, too.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AKX