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

vakul bhatt vakulb5678 at gmail.com
Wed Jun 19 10:28:56 EDT 2019


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



More information about the Python-list mailing list