libkeepass / pykeepass

Python library to interact with keepass databases (supports KDBX3 and KDBX4)
https://pypi.org/project/pykeepass/
GNU General Public License v3.0
403 stars 96 forks source link

etree.tostring encoding parameter is set to "unicode", which seems to be invalid #395

Closed borland502 closed 3 weeks ago

borland502 commented 1 month ago

bug location in pykeepass.py, line 275

    def xml(self):
        """Get XML part of database as string

        Returns:
            str: XML payload section of database.
        """
        return etree.tostring(
            self.tree,
            pretty_print=True,
            standalone=True,
            encoding='unicode'
        )

To reproduce

        kp_db = PyKeePass(filename=db_path, keyfile=key_path, password=token_path.read_text(encoding="utf-8"))
        # Hack: Take care of what seems to be a bug in pykeepass when exporting xml
        foo = kp_db.xml()  #.replace("encoding=''", "encoding='utf-8'")
        test = pd.read_xml(encoding="utf-8", path_or_buffer=foo)

Pandas will raise an invalid encoding error since the encoding tag is present, but empty.

Evidlo commented 3 weeks ago

Fixed in 4.0.8