I'm setting up a simple Python3.X server, but there is a TypeError that I can't solve.

I've tried this type of server on a Ubuntu Desktop machine, but on a Raspberry Pi Zero W, it does not seem to work.

def main():
    socket.bind(('', 8000))
    socket.listen(5)

    while True:
        connection, address = socket.accept()
        data = connection.recv(1024)
        data = data.decode()
        data_bak = data

It should be working, but this error shows up:

TypeError: a bytes-like object is required, not 'tuple'

I verified, but there is no 'tuple' in my code

1 Answers

0
Devesh Kumar Singh On

You would want to define a socket object first, and then call bind on that object, and then call subsequent function on that socket object

A good starting example is here

In [18]: from socket import socket                                                                                                                        
In [19]: s = socket()                                                                                                                                     
In [20]: s.bind(('',8000))  
In [21]: s.listen(5)                                                                                                                                      
In [22]: