Reputation: 180
I got this error:
AttributeError: 'str' object has no attribute 'encrypt'
when running these lines of code. They are inside definition of a function(except for the import lines). Btw from which library is the function encrypt()
?
import socket
import sys
import getopt
import threading
import subprocess
buffer="lol"
client_sender(buffer.encrypt('utf-8'))
Upvotes: 1
Views: 1660
Reputation: 360
You probably want to go with
buffer.encode('utf8')
in order to make the string a byte object and pass it to a socket connection.
Upvotes: 1
Reputation: 102852
If you are trying to convert a str
to a bytes
object, the proper method is str.encode()
:
>>> s = "foo"
>>> s.encode("utf-8")
b'foo'
Upvotes: 1