TypeError: Data must not be unicode
生活随笔
收集整理的這篇文章主要介紹了
TypeError: Data must not be unicode
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在學習twisted的過程中,遇到的第一個例子就出了點問題。
self.transport.write("Hello World!")在運行的時候會拋出以下錯誤
File "/usr/local/lib/python3.7/site-packages/twisted/internet/selectreactor.py", line 149, in _doReadOrWritewhy = getattr(selectable, method)()File "/usr/local/lib/python3.7/site-packages/twisted/internet/tcp.py", line 627, in doConnectself._connectDone()File "/usr/local/lib/python3.7/site-packages/twisted/internet/tcp.py", line 656, in _connectDoneself.protocol.makeConnection(self)File "/usr/local/lib/python3.7/site-packages/twisted/internet/protocol.py", line 514, in makeConnectionself.connectionMade()File "echoclient.py", line 8, in connectionMadeself.transport.write("Hello World!")File "/usr/local/lib/python3.7/site-packages/twisted/internet/_newtls.py", line 191, in writeFileDescriptor.write(self, bytes)File "/usr/local/lib/python3.7/site-packages/twisted/internet/abstract.py", line 349, in writeraise TypeError("Data must not be unicode") builtins.TypeError: Data must not be unicode?解決辦法就是把string類型的字符串,轉為字節類型的字符串
"Hello World!".encode() 或者 "Hello World!".encode('utf-8') 或者 b"Hello world!"總結
以上是生活随笔為你收集整理的TypeError: Data must not be unicode的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 文件操作一(写文件、按行读文件
- 下一篇: python 学习笔记 - for循环: