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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:00+00:00 2026-05-25T14:23:00+00:00

>>> from lxml import objectify >>> from StringIO import StringIO >>> f = StringIO(<root>data</root>)

  • 0
>>> from lxml import objectify
>>> from StringIO import StringIO
>>> f = StringIO("<root>data</root>")
>>> tree = objectify.parse(f)
>>> type(tree)
<type 'lxml.etree._ElementTree'>
>>> tree.find('root')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lxml.etree.pyx", line 1944, in lxml.etree._ElementTree.find (src/lxml/lxml.etree.c:45105)
TypeError: find() takes exactly one argument (2 given)
>>> tree.find()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lxml.etree.pyx", line 1926, in lxml.etree._ElementTree.find (src/lxml/lxml.etree.c:44970)
TypeError: find() takes at least 1 positional argument (0 given)
>>> print tree.find.__doc__
find(self, path, namespaces=None)

        Finds the first toplevel element with given tag.  Same as
        ``tree.getroot().find(path)``.

        The optional ``namespaces`` argument accepts a
        prefix-to-namespace mapping that allows the usage of XPath
        prefixes in the path expression.

Note that tree.getroot().find works and find works on _ElementTree instances created by etree.parse.

Tha main question: how can the same method raise these two mutually exclusive exceptions? Also, while I can use tree.getroot().find, the shorter form would be preferred if it worked as documented, so I’m curious, is it a lxml bug?

  • 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-25T14:23:00+00:00Added an answer on May 25, 2026 at 2:23 pm

    We solve this mystery by looking at the corresponding source (long live OSS):

    def find(self, path, namespaces=None):
        u"""find(self, path, namespaces=None)
    
        Finds the first toplevel element with given tag.  Same as
        ``tree.getroot().find(path)``.
    
        The optional ``namespaces`` argument accepts a
        prefix-to-namespace mapping that allows the usage of XPath
        prefixes in the path expression.
        """
        self._assertHasRoot()
        root = self.getroot()
        if _isString(path):
            start = path[:1]
            if start == u"/":
                path = u"." + path
            elif start == b"/":
                path = b"." + path
        return root.find(path, namespaces)
    

    "lxml.etree.pyx", line 1926 is the first and "lxml.etree.pyx", line 1944 the last line of the sniplet, so there are in fact two different find methods. Apparently objectify constructs some different objects (and thus this is a bug in lxml) that do not accept the namespaces parameter. If you use lxml.etree.parse to parse your StringIO object, the API works just fine.

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

Sidebar

Related Questions

I parse in the XML using from lxml import etree tree = etree.parse('test.xml', etree.XMLParser())
Here's the code I have: from cStringIO import StringIO from lxml import etree xml
In [1]: from lxml import etree I've got an HTML document: In [2]: root
Using lxml.objectify like so: from lxml import objectify o = objectify.fromstring(<a><b atr='someatr'>oldtext</b></a>) o.b =
I have an lxml.objectify data structure I get from a RESTful web service. I
I'm trying to parse an xml file using lxml. xml.etree allowed me to simply
I have the following code: from lxml.builder import ElementMaker E = ElementMaker() params =
I have tho following code fragment: from xml.etree.ElementTree import fromstring,tostring mathml = fromstring(input) for
I have an xml file that I'm using etree from lxml to work with,
From what information I could find, they both solve the same problems - more

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.