Python3 TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Question:

I have been trying to follow along with a tutorial, but have been getting the error in the title when I try to click create a game in a client window. I ended up copying and pasting the code into pycharm and still got the same error. I’ve linked the website where the tutorial’s source code can be found.

Asked By: darththomas

||

Answers:

Apparently your game client cannot get connection to server.

n = Network()
player = int(n.getP()) # <<< here you got an exception

class Network:
def __init__(self):
    self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.server = "10.11.250.207"
    self.port = 5555
    self.addr = (self.server, self.port)
    self.p = self.connect()  # <<< this value is of None type

def getP(self):
    return self.p

def connect(self):
    try:
        self.client.connect(self.addr)
        return self.client.recv(2048).decode()  # << somewhere here an exception occures
    except:  # <<< but it gets cought here
        pass # <<< and method returns None

Are you sure you have your server running? You must run it in separate console window simultaniously with client.

Answered By: Michail Highkhan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.