Jessica Warren
Jessica Warren

Reputation: 398

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?

Upvotes: 4

Views: 2667

Answers (2)

Robᵩ
Robᵩ

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

Bubble Bubble Bubble Gut
Bubble Bubble Bubble Gut

Reputation: 3358

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

Upvotes: 4

Related Questions