[New-bugs-announce] [issue41759] ElementTree.parse gives error message about missing1 required positional argument: 'source' but it is there

Freek de Kruijf report at bugs.python.org
Fri Sep 11 05:22:51 EDT 2020


New submission from Freek de Kruijf <f.de.kruijf at gmail.com>:

In a function definition I have the following piece of code:

    try:
        with open(requests,'rt') as f:
            tree = ElementTree.parse(f)

On execution I got:

Traceback (most recent call last):
   File "/srv/www/bin/web.py", line 362, in <module>
     build_db()
   File "/srv/www/bin/web.py", line 58, in build_db
     db_builder.build_DB()
   File "/srv/www/bin/db_builder.py", line 190, in build_DB
     tree = ElementTree.parse(f)
 TypeError: parse() missing 1 required positional argument: 'source'

There is an assignment for requests like
requests = '..' + os.path.sep + "/etc/signatures.xml"
This gives requests the value ..//etc/signatures.xml while the program runs in /srv/www/bin/

When I run the small python script like:

import xml.etree.ElementTree as ElementTree
with open('/srv/www/etc/signatures.xml','rt') as f:
    tree = ElementTree.parse(f)

all is well.
Apparently open(requests,'rt') does not raise an error.

----------
components: Extension Modules
messages: 376706
nosy: f.de.kruijf
priority: normal
severity: normal
status: open
title: ElementTree.parse gives error message about missing1 required positional argument: 'source' but it is there
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41759>
_______________________________________


More information about the New-bugs-announce mailing list