S.send command in python

Hi, i´m trying to send → s.send (“set_digital_out(2,False)” + “\n”) , but i get TypeError: a bytes-like object is required, not ‘str’.
Does anyone know a solution? Thanks!
Code:

Echo client program

import socket

import time

HOST = “172.16.200.62” # The remote host

PORT = 30002 # The same port as used by the server

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((HOST, PORT))

s.send (“set_digital_out(2,False)” + “\n”)

s.send (“running”+“\n”)

data = s.recv(1024)

s.close()

print (“Received”, repr(data))

Hello I would suggest using the encode methode.

msg = “set_digital_out(2,False)” + “\n”
s. send(msg.encode())

to print the received data i would use print(data.decode())

Thanks!! Nice week!!

1 Like

Hello, the problem is for python3 you must change the SEND command like this:
s.send(str.encode(‘set_standard_digital_out(2,False)\n’))