I'm using Twisted 16.1.1 and python 3.4. On twisted's documentation for version 16.1.1, there is a tutorial that says `from twisted.spread import pb'. But when I try to import it it gives an exception. What am I doing wrong?
Traceback (most recent call last):
File "main.py", line 10, in <module>
from twisted.spread import pb
ImportError: cannot import name 'pb'
I'm follwing this tutorial. This is my code:
from twisted.internet import reactor
from twisted.spread import pb
class Echoer(pb.Root):
def remote_echo(self, st):
print('echoing:', st)
return st
if __name__ == '__main__':
reactor.listenTCP(8789, pb.PBServerFactory(Echoer()))
reactor.run()
On /usr/lib64/python3.4/site-packages/twisted/spread
there is on one folder named ui
. There is not a folder/file called pb.
I copied the pb.py
file to my python folder, now when I try to import pb I get an Exception:
Traceback (most recent call last):
File "main.py", line 2, in <module>
from twisted.spread import pb
File "/usr/lib64/python3.4/site-packages/Twisted-16.1.1-py3.4.egg/twisted/spread/pb.py", line 890
except Error, e:
^
SyntaxError: invalid syntax
What is happening?
The reason for the SyntaxError is that except Error, e:
in only valid in Python 2. In Python 3, it would be written except Error as e:
.
The problem isn't with your code. The underlying module hasn't yet been updated to Python 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With