[Python] Adding text file attachments to Keepass with pykeepass in python

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create and save KeePass entries using pykeepass and saving a .txt file as an attachment. However I get a type-error:

    TypeError: bad argument type: bytes(b'Lorem Impsum bla bla bla')


    My minimal reproducible example is:

    from pykeepass import PyKeePass

    kp = PyKeePass('testDatabase.kdbx', password='passwort')

    generalGroup = kp.find_groups(name='General',first=True)
    entry = kp.add_entry(
    generalGroup,
    title='title',
    username='username'
    password= 'password'
    )

    with open('loremipsum.txt', 'rb') as f:
    entry.add_attachment('attachment.txt', f.read())

    kp.save()



    (All files are in the same directory, the file loremipsum.txt contains the line: "Lorem Impsum bla bla bla")

    How do I have to convert the file content of a .txt-file to Bytes?

    I am using the pykeepass Version: 4.1.0.post1, Keepass Version 2.58 and Python 3.13.

    Continue reading...

Compartilhe esta Página