Skip to content

XMPP servers and errors

The PubSub service

Every operation takes the address of the PubSub service as its first argument (target_jid). It is a component of the XMPP server, usually pubsub.<domain>: pubsub.localhost for agents like agent@localhost.

The XMPP server of SPADE

The XMPP server of SPADE (PyJabber) has a PubSub service at pubsub.<domain>, with no configuration. Start it in a terminal:

spade run

or run it with your program:

if __name__ == "__main__":
    spade.run(main(), embedded_xmpp_server=True)

Any agent can create nodes, and its nodes behave as described in these guides: only the owner publishes, the owner and the subscribers read the items, and retractions are always notified. The configuration of the nodes is not applied yet (PyJabber 0.5.1).

Use if __name__ == "__main__":

The XMPP server of SPADE runs some work in other processes. On Python 3.14 (and on macOS and Windows), they import your script again: without the if __name__ == "__main__": guard, each of them would run your program and start another XMPP server, and the agents fail to connect.

Other XMPP servers

Most XMPP servers have a PubSub service, but they may need some configuration:

  • Prosody: enable the PubSub component in the configuration (Component "pubsub.example.com" "pubsub"). If the creation of nodes is restricted (restrict_node_creation = true), only the admins can create nodes: add your agents to admins, or allow everyone.
  • ejabberd: mod_pubsub is enabled by default, at pubsub.<host>. Who can create nodes is set by its access_createnode option.
  • Openfire: PubSub is enabled by default, at pubsub.<domain>. Who can create nodes is set in Server > Server Settings > PubSub.

They apply the node configuration: the default access model, publish model, number of items kept... may differ from the XMPP server of SPADE.

Errors

The operations do not raise exceptions when the service answers with an error (e.g. the node does not exist, or the agent is not allowed), or does not answer in time: the error is logged, and the operation returns None, or an empty list for get_nodes(), get_items() and get_node_subscriptions().

Check the result when it matters:

if await self.agent.pubsub.create(PUBSUB, "news") is None:
    print("The node could not be created")

The errors are logged with loguru at the ERROR level, and include the answer of the service, with the error condition (item-not-found, forbidden, conflict...):

ERROR | spade_pubsub.pubsub:create - Error creating node <news>: <iq type="error" ...><error type="cancel">
<conflict xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>