Python Forum
typeerror:byte like object is required
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
typeerror:byte like object is required
#1
#server.py
import socket # Import socket module
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
while True:
print("waiting for client connection" )
c, addr = s.accept() # Establish connection with client.
print ('Got connection from', addr)
c.send('Thank you for connecting'))
c.close() # Close the connection
#client.py
import socket # Import socket module
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.connect((host, port))
print(s.recv(1024))
s.close # Close the socket when done
Reply
#2
Quote:
s.close # Close the socket when done

Your comment doesn't match your code. If you want to close the socket, you need to call the close() function. Just referencing the function doesn't call it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,394 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  I am getting this TypeError: 'TreasureMap' object is not subscriptable. makilakos 2 1,241 May-25-2024, 07:58 PM
Last Post: deanhystad
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 2,719 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 1,745 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 3,603 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 14,001 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 5,610 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable #1 isdito2001 1 1,900 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 15,641 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 3,525 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020