Tyler Grim
Tyler Grim

Reputation: 35

Assertion error with snakemq python 3.2.1

I'm working through the tutorial found here: http://www.snakemq.net/doc/tutorial.html

Here is my code:

import snakemq.link
import snakemq.packeter
import snakemq.messaging
import snakemq.message

#Build Stack

my_link = snakemq.link.Link()
my_packeter = snakemq.packeter.Packeter(my_link)
my_messaging = snakemq.messaging.Message("tyler", "", my_packeter)

#Tyler

my_link.add_listener(("", 4000))
my_link.add_connector(("localhost", 4001))

#Sally

my_link.add_connector(("localhost", 4000))
my_link.add_connector(("localhost", 4001))

#Paul

my_link.add_connector(("localhost", 4000))
my_link.add_listener(("", 4001))

#Run link loop (it drives the whole stack)

my_link.loop()

#Tyler wants to send a message to Sally
#drop after 30 seconds if the message can't be delivered

message = snakemq.message.Message(b"Hello", ttl = 600)
my_messaging.send_message("Sally", message)

#receiving callback

def on_recv(conn, ident, message):
    print(ident, message)

my_messaging.on_message_recv.add(on_recv)

I receive the error:

Traceback (most recent call last):
File "C:/Users/Owner/Desktop/snakemq tutorial/test.py", line 10, in my_messaging = snakemq.messaging.Message("tyler", "", my_packeter)
File "C:\Python32\lib\site-packages\snakemq-1.2-py3.2.egg\snakem\message.py",
line 30, in init assert type(data) == bytes
AssertionError

Upvotes: 1

Views: 364

Answers (1)

Anthony Kong
Anthony Kong

Reputation: 40844

Looks like you are building the Message incorrectly.

According to the doc, http://www.snakemq.net/doc/api/messaging.html#message, the constructor is

class snakemq.message.Message(data, ttl=0, flags=0, uuid=None)

But in this line,

my_messaging = snakemq.messaging.Message("tyler", "", my_packeter)

you are passing "tyler", "" and my_packeter which do not match the function definition.

You should try this

my_messaging = snakemq.messaging.Message(b"tyler")

Upvotes: 0

Related Questions