Search code examples
pythonpython-3.xtwistedrtsp

Twisted TypeError in sendLine


I am using python-RTSP to run RTSP using Twisted and Python3. I am trying access RTSP information for the youtube link using above configuration. Ihave to use Python3 as my remaining code is in Python3.

I am sending command using

self.sendLine('%s %s RTSP/1.0' % (command, path))

where Command is DESCRIBE and Path is the url

rtsp://r7---sn-a5m7zu7d.c.youtube.com/CiILENy73wIaGQlFHOtrHD-E8RMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp

I get Error with following statement:

File "/home/akshay_v/valuconnex-python/twisted/protocols/basic.py", line 637, in sendLine
        return self.transport.write(str(line + self.delimiter))
    builtins.TypeError: Can't convert 'bytes' object to str implicitly

self.delimiter = b'\r\n'
line is the *str* passed as argument in above statement.

How to get this working?


Solution

  • As Jean-Paul says, you can't use Python 3 to run python-RTSP.

    If you're curious about the exact nature of this failure, the issue is that transport.write takes a bytes object. On Python 2 that is the same type as str, on Python 3 it is its own type. The type that is analagous to Python 3's str on Python 2 is unicode, and you can't write unicode to a socket, so you can't pass it to transport.write.

    However, the line of code you're showing there in twisted.protocols.basic looks like an incorrectly-modified version of Twisted; I can't find a version of Twisted that has ever called str in that location. How did you get this version of Twisted, and have you tried upgrading to the most recent release (14.0.0 as of this writing)?