Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write this in a way that python does not interpret the data as unicode?

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?

like image 555
Jessica Warren Avatar asked Jan 03 '23 00:01

Jessica Warren


2 Answers

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')
like image 56
Robᵩ Avatar answered Jan 05 '23 14:01

Robᵩ


It's seems like you're building a server, try using b'Hello World' to convert to bytes.

like image 37
Bubble Bubble Bubble Gut Avatar answered Jan 05 '23 16:01

Bubble Bubble Bubble Gut