Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:19:36+00:00 2026-05-31T21:19:36+00:00

so… I have a simple chat client like so: class ChatClient(sleekxmpp.ClientXMPP): def __init__(self, jid,

  • 0

so… I have a simple chat client like so:

class ChatClient(sleekxmpp.ClientXMPP):
    def __init__(self, jid, password, server):
        sleekxmpp.ClientXMPP.__init__(self, jid, password, ssl=True)

        self.add_event_handler("session_start", self.start)

        self.register_plugin('xep_0030')
        self.register_plugin('xep_0004')
        self.register_plugin('xep_0060')
        self.register_plugin('xep_0199')

        self.ssl_version = ssl.PROTOCOL_SSLv3
        self.connected = self.connect()
        if self.connected:
            self.process(threaded=True)


    def start(self, event):
        self.send_presence(priority = "-9001")
        self.get_roster(blocking = True, timeout = 3)

    def message(self, targets, msg):
        for target in targets:
            self.send_message(target, msg)

and I have an “verify” function to make sure you input your username/pass right:

def authenticate(username, password, server):
    xmppuser = username + '@' + server
    passTester = ChatClient(xmppuser, password)

    passTester.disconnect(wait = True)
    authenticated = passTester.authenticated
    return authenticated

Now, the problem comes in where I have the chat client as threaded, I run into the situation where I try to check ChatClient.authenticated before the server had a chance to actually connect. As you can see, I tried to “wait” on the disconnect but there’s nothing in the send queue so it disconnects right away.

An alternate I tried is this:

def authenticate(username, password, server):
    xmppuser = username + '@' + server
    passTester = ChatClient(xmppuser, password)

    passTester.message('bogusName', 'ladfhkjdglkhjdfg')
    passTester.disconnect(wait = True)
    authenticated = passTester.authenticated
    return authenticated

Now that I sent a bogus message the disconnect call has something to wait for. when I input a correct username/pass with this code, the disconnect waits for a message to get sent (which involves waiting for a real connection), sends nothing and ChatClient.authenticated is set to True!

Unfortunately, when I input a wrong username/pass the message never gets sent and the disconnect(wait=True) never disconnects as the message never gets sent.

Does anyone else have a more proper way to “authenticate”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:19:37+00:00Added an answer on May 31, 2026 at 9:19 pm

    This would be a good reason for changing the .authenticated and related fields to be threading.Event objects so that you could use wait() for situations like this, but I’m not sure how much that would break existing user code.

    But short of modifying SleekXMPP, what you will need to do is wait for certain events to fire. For example, if your client successfully authenticated, then there will be a session_start event (I may add an auth_success or similar event later). Likewise, if authentication failed for a single mechanism, there will be a failed_auth event. If no authentication methods at all succeeded (which is what you’d be interested in), there will be a no_auth event.

    So you can add handlers for these events, and have those handlers place a token in a queue, and then wait for the desired token to arrive.

    class ChatClient(ClientXMPP):
        def __init__(self, ...):
            ...
            self.auth_queue = queue.Queue()
            self.add_event_handler('no_auth', self.failed)
    
        def start(self, event):
            self.auth_queue.put('success')
            ...
    
        def failed(self, event):
            self.auth_queue.put('failed')
    
    
    def authenticate(username, password, server):
        xmppuser = username + '@' + server
        passTester = ChatClient(xmppuser, password)
        try:
            result = passTester.auth_queue.get(timeout=10)
        except queue.Empty:
            result = 'failed'
        passTester.disconnect()
        return result == 'success'
    

    Don’t forget that we also have the chat room at sleek@conference.jabber.org.

    — Lance

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
I have been making a wordpress template. i got stuck at some place... the
I've successfully connected to XMPP server (from android XMPP client), and I can send
I have a form, one of the fields is a select field, with 5
I see that some rss on xml have strange strings. For example, ... is
I have a PDB file. Now it has two parts separated by TER. Before
An Arabic name shall be sent via SOAP. The name is encoded like this:
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.