osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

s.sendall(filename + "\r\n") TypeError: a bytes-like object is required, not 'str'


Hi Team,

i m new to python, running below program, getting error
Python Version : 3.7 32bit for windows
Program:
============================
#simple Goopher client

import socket, sys

port = 70
host = sys.argv[1]
filename = sys.argv[2]

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))

s.sendall(filename + "\r\n")

while 1:
  buf = s.recv(2048)
  if not len(buf):
    break
  sys.stdout.write(buf)
============================


Error :

============================
python goopher.py quux.org /
Traceback (most recent call last):
  File "goopher.py", line 13, in <module>
    s.sendall(filename + "\r\n")
TypeError: a bytes-like object is required, not 'str'

============================

please help.


thanks & Regards