XMPP pub sub setup and working

dieter dieter at handshake.de
Sun Dec 13 06:34:34 EST 2015


satish at driveu.in writes:

> I am using xmpppy python library to connect with XMPP server(ejabberd2) but unable to connect and actually don't have clarity on how to connect, authenticate and send a message to the server.  
> If possible please provide some code snippet using XMPPPY.
>
> This is what I have tried:
>
> In [1]: from xmpp import Client
>
> In [2]: cl = Client(server='176.9.18.111', 5280)
>
>   File "<ipython-input-2-ae974e3ec546>", line 1
>
>     cl = Client(server='176.9.18.111', 5280)
>
> SyntaxError: non-keyword arg after keyword arg

A wrong call of the "Client" class:

  If you pass a parameter value in the form "<name>=<value>"
  (which you do for "server"), this is called a "keyword arg[ument]".
  If you pass it in the form "<value>", this is called
  a "positional" or "non keyword arg[ument]".

  The error message tells you that you must not pass
  a positional argument after a keyword argument (what you
  do above).

Likely, you can use "Client('176.9.18.111', 5280)" or
"Client(server='176.9.18.111', port=5280)".
Both should get rid of the "SyntaxError" - but, of course,
you still have the issue with authentication.

Have a look at the so called "signature" of "Client".
The "signature" of a callable (usually function, method or class)
tells you what parameters are available and what names
(and potentially default values) they have.
You might find in the signature for "Client" parameters which
hint towards authentication (e.g. "user" and "password").
If so, pass values identifying yourself.


I heavily use Python's builtin "help" function:
"help(obj)" provides documentation for object "obj".
Thus, "help(Client)" will display information about "Client".
If it is indeed a class (which I assume), then the documentation
will (among others) list the methods. The signature for "Client"
is in this case, the signature of its "__init__" method (without
the initial "self").


> In [3]: cl = Client(server='176.9.18.111', port =5280)
> Invalid debugflag given: always
> Invalid debugflag given: nodebuilder
> DEBUG: 
> DEBUG: Debug created for /Users/gathole/.virtualenvs/driveu/lib/python2.7/site-packages/xmpp/client.py
> DEBUG:  flags defined: always,nodebuilder

The output above is a bit strange - are you sure, you did not
have requested debugging in some way (not shown above)?

> In [4]: cl.connect()
> ...
> DEBUG: socket       sent  <?xml version='1.0'?>
>   <stream:stream xmlns="jabber:client" to="176.9.18.111" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" >
> DEBUG: socket       error Socket error while receiving data
> DEBUG: client       stop  Disconnect detected

Apparently, the server was not satisfied with the connection
proceedure and has closed the communication stream.

Check available documentation for the server you try to connect
about the connection requirements.
If there is no such documentation, you might try to contact
the server administrator to find out the relevant details.




More information about the Python-list mailing list