Reputation: 398
CODE:
class EchoClient(protocol.Protocol):
def connectionMade(self):
self.transport.write("Hello World!")
Error:
##raise TypeError("Data must not be unicode") builtins.TypeError: Data must not be unicode ##
How do i write the code to be utf-8?
Upvotes: 4
Views: 2667
Reputation: 168726
Assuming you are using Python3, try:
"Hello World!".encode('utf-8')
If your data is in a str
variable, try:
# s = "Hello World!"
s.encode('utf-8')
Upvotes: 5
Reputation: 3358
It's seems like you're building a server, try using b'Hello World'
to convert to bytes.
Upvotes: 4