【发布时间】:2013-10-05 08:41:45
【问题描述】:
我使用 ws4py 0.3.2 创建了一个 Web 服务器套接字,它在 python 3.3.2 上使用了 cherrypy 3.2.4。当我尝试打印客户端发送到服务器的消息时,例如 this
class ChatWebSocketHandler(WebSocket):
def received_message(self, m):
cherrypy.log("[+] Message => {%d} %s" % (len(m), m))
cherrypy.engine.publish('websocket-broadcast', m)
我收到错误消息:
File "./server.py", line 13, in received_message
cherrypy.log("[+] Message => {%d} %s" % (len(m), m))
TypeError: __str__ returned non-string (type bytes)
【问题讨论】:
-
将
cherrypy.log("[+] Message => {%d} %s" % (len(m), m))替换为cherrypy.log("[+] Message => {%d} %r" % (len(m), m))。然后会发生什么? -
输出关闭
cherrypy.log("[+] Message => {%d} %r" % (len(m), m))是:[+] Message => {46} <ws4py.messaging.TextMessage object at 0x7f15d8785650>
标签: python-3.x cherrypy ws4py