1

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?

Eranki
  • 750
  • 1
  • 11
  • 30
  • Your example is a bit too small. It can't be run to reproduce the problem and it doesn't clearly hint at the location of the problem. Try making the example in the question self-contained and complete. – Jean-Paul Calderone Jun 07 '23 at 11:11
  • Hi, I'm facing same problem; have you found any solution @Eranki? – Abdulkarim Kanaan Jun 30 '23 at 12:37
  • Yes, I found. Is your problem statement also same? – Eranki Jul 07 '23 at 06:27
  • In my case I have a eventsockey.py file. This file has class EventSocket that inherits basic.LineReceiver. Inside this class, delimiter variable is str type. Make it to byte type and it fixed my issue. Post fixing this I had some other errors which I am unable to recall and those are not so hard ones as well. Why do we have to make it to bytes? Because the data in previously was received in string form and now it is bytes. – Eranki Jul 07 '23 at 06:33

0 Answers0