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 7969115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:11:12+00:00 2026-06-04T07:11:12+00:00

I am new in python and I am trying to create a testing python

  • 0

I am new in python and I am trying to create a testing python script to test different actions on my XMPP server. I already was able to test the login of my user and now I want to get the information that the server is sending (stanza) and set new information.

I have read several webs and I am not very clear with all this information. The main source has been sleekxmpp.com.

I have my stanza:

<iq type='get' to= 'chat.net'  id='id1'>
  <aa xmlns='http://myweb.com' />
</iq>

<iq type='result' to= 'chat.net'  id='id1'>
  <aa xmlns='http://myweb.com' >
    <name>My name as included in sent mails<name>
  <lang>en</lang>
    <mail>My mail as included in sent mails</mail>
  </aa>
</iq>

I want to get the information and also set one of the parameters (lets say name) but I don’t know how.

class user_info(sleekxmpp.stanza.Iq):

    self.get_query()

I must do it in python. Any help appreciated

  • 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-06-04T07:11:12+00:00Added an answer on June 4, 2026 at 7:11 am

    What you want to do is create a custom stanza class for your stanza. Here’s one that will work for the example you have:

    from sleekxmpp import Iq
    from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin
    
    class AA(ElementBase):
        name = 'aa'
        namespace = 'http://myweb.com'
        plugin_attrib = 'aa'
        interfaces = set(['name', 'lang', 'mail'])
        sub_interfaces = interfaces
    
    register_stanza_plugin(Iq, AA)
    

    Ok, so what does all of that do? The name field specifies that the XML object’s root tag is ‘aa’, and namespace specifies the root tag’s namespace; obvious so far I hope.

    The plugin_attrib field is the name that can be used to access this stanza from the parent stanza. For example, you should already be familiar with how you can use iq['type'] or iq['from'] to extract data out of an Iq stanza. With plugin_attrib set to "aa", then you can use iq['aa'] to get a reference to the AA content.

    The interfaces set is the set of key names that this stanza provides for extracting information, just like working with dictionaries. For example an Iq stanza has ‘to’, ‘from’, ‘type’, etc in its interfaces set. By default, accessing and modifying these keys will create or modify attributes of the stanza’s main element. So, at this point, your stanza would behave like this:

    aa = AA()
    aa['name'] = 'foo'
    print aa
    "<aa xmlns='http://myweb.com' name='foo' />"
    

    Now, to instead map interface keys to subelements instead of attributes, they need to be in the sub_interfaces set. So by setting sub_interfaces = interfaces the above example would now work like so:

    aa = AA()
    aa['name'] = 'foo'
    print aa
    "<aa xmlns='http://myweb.com'><name>foo</name></aa>"
    

    If you needed something more advanced, you could also define methods of the form get_* / set_* / del_* where * is the interface name which will then be used to extract or modify data.

    So, all together, you will be able to do:

    iq = Iq()
    # ... set iq parameters
    iq.enable('aa')  # Add an initial, empty aa element.
    try:
        resp = iq.send()
        print(resp['aa']['name'])
        # ..., etc
    except XMPPError:
        print('There was an error')
    

    Also, don’t forget that we have the sleek@conference.jabber.org chat room for SleekXMPP help if you need it.

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

Sidebar

Related Questions

I'm trying to create an environment using virtualenv. virtualenv test New python executable in
I'm trying to create a new FileCookieJar using cookielib in Python 2.6. However, when
I am very new to Python, and trying to figure out how to create
I am new to python and trying to create a bloomFilter based on Bit
I am trying to create a python script that opens a single page at
I've been trying to create new blog posts on my site using python and
I'm very new to python (just started yesterday), and I'm trying to create permutations
I am new to python and I am trying to create a capitalize function
I'm new to Python and I'm trying to create a simple GUI using Tkinter.
I am new to python and I'm trying to create a program that creates

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.