I'm using python3.8 and twisted 22.10.0. I'm connecting freeswitch with reactor and using a event socket to handle the events.I'm able to make TCP connection with freeswitch and after executing the reactor thread I get the following error
Unhandled Error
Traceback (most recent call last):
File "/home/.local/lib/python3.8/site-packages/twisted/python/log.py", line
96, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/home/.local/lib/python3.8/site-packages/twisted/python/log.py", line
80, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/home/.local/lib/python3.8/site-packages/twisted/python/context.py",
line 117, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/home/.local/lib/python3.8/site-packages/twisted/python/context.py",
line 82, in callWithContext
return func(*args, **kw)
--- <exception caught here> ---
File "/home/.local/lib/python3.8/site-packages/twisted/internet/posixbase.py",
line 487, in _doReadOrWrite
why = selectable.doRead()
File "/home/.local/lib/python3.8/site-packages/twisted/internet/tcp.py", line
249, in doRead
return self._dataReceived(data)
File "/home/.local/lib/python3.8/site-packages/twisted/internet/tcp.py", line
256, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/home/.local/lib/python3.8/site-packages/twisted/protocols/basic.py",
line 542, in dataReceived
line, self._buffer = self._buffer.split(self.delimiter, 1)
builtins.TypeError: a bytes-like object is required, not 'str'
My snippet of what I'm trying:
from twisted.internet import protocol, reactor
factory = MyFactory()
reactor.connectTCP('127.0.0.1', 8021, factory)
reactor.run(installSignalHandlers=0)
class MyFactory(protocol.ReconnectingClientFactory):
def __init__(self):
self.password = '----'
MyFactory.stopDeferred = defer.Deferred()
def buildProtocol():
some code here to build protocol
return protocol
I kept console in the basic.py
and found that self._buffer and self.delimeter are both byte types. And I beleive it's not advisble to typecast to string in this file.
How do I get over this error?