在Python 3.7(macOS)上运行扭曲的示例脚本会引发异常

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Python 3.7(macOS)上运行扭曲的示例脚本会引发异常相关的知识,希望对你有一定的参考价值。

我想用Python 3.7.5macOS Catalina 10.15.1上运行的19.7.0进行扭曲。

我选择聊天示例以验证其是否有效(请参阅https://twistedmatrix.com/documents/current/core/howto/servers.html中的chat.py源代码。

根据文档,我已经使用twisted安装了virtualenv

我启动脚本,然后用telnet测试它:

telnet 127.0.0.1 8123

它遵循堆栈跟踪:

Unhandled Error
Traceback (most recent call last):
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/internet/selectreactor.py", line 149, in _doReadOrWrite
    why = getattr(selectable, method)()
--- <exception caught here> ---
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/internet/tcp.py", line 1435, in doRead
    protocol.makeConnection(transport)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/internet/protocol.py", line 514, in makeConnection
    self.connectionMade()
  File "/Users/giacomo/pyenvs/twisted-samples/chat.py", line 13, in connectionMade
    self.sendLine("What's your name?")
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/protocols/basic.py", line 636, in sendLine
    return self.transport.write(line + self.delimiter)
builtins.TypeError: can only concatenate str (not "bytes") to str

Unhandled Error
Traceback (most recent call last):
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/python/log.py", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/internet/selectreactor.py", line 149, in _doReadOrWrite
    why = getattr(selectable, method)()
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/internet/tcp.py", line 243, in doRead
    return self._dataReceived(data)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/internet/tcp.py", line 249, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/protocols/basic.py", line 572, in dataReceived
    why = self.lineReceived(line)
  File "/Users/giacomo/pyenvs/twisted-samples/chat.py", line 21, in lineReceived
    self.handle_GETNAME(line)
  File "/Users/giacomo/pyenvs/twisted-samples/chat.py", line 29, in handle_GETNAME
    self.sendLine("Welcome, %s!" % (name,))
  File "/Users/giacomo/.virtualenvs/twisted-samples/lib/python3.7/site-packages/twisted/protocols/basic.py", line 636, in sendLine
    return self.transport.write(line + self.delimiter)
builtins.TypeError: can only concatenate str (not "bytes") to str

我的系统Python是2.7.16,版本3已安装brew

如果我需要发布有关系统的更多信息,请告诉我。

答案
None

以上是关于在Python 3.7(macOS)上运行扭曲的示例脚本会引发异常的主要内容,如果未能解决你的问题,请参考以下文章

macOS Document App SwiftUI 项目上的 NSPersistentDocument FetchRequest 扭曲属性崩溃

没有模块 QtMultimedia [Mac OS - Anaconda - Python 3.7 - PyQt5]

在 MacOS Mojave 上为 QGIS 安装 Python 3.6

如何为在 64 位 Amazon Linux 2 上运行的 Elastic Beanstalk Python 3.7 项目安装节点包?

安装 python@3.7 MacBook Air m1 问题

Python 将 http post body 扭曲转发到 tcp 端口